Taking Qry And Then Having It Order By In A Table

Jan 18, 2008

I have one query with 3 statments in it, which then creates a table called HCSReturnFile. My problem is that I have an order by in my query, but when I go to create a table that puts all 2 statements into 1, it does not do the order by. What am I doing wrong? Below is my Query.

USE [Impact_PROD]
GO
/****** Object: StoredProcedure [dbo].[p_GenerateHCSReturnFileUPDATE] Script Date: 01/18/2008 14:20:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:Wendy & Mike
-- Create date: 11/08/2007
---Create Date to Production - 12-06-2007
-- Description:This was a touch one.
---This report drop both Queries into a tabled called HCSRetrunFile
-- =============================================
ALTER PROCEDURE [dbo].[p_GenerateHCSReturnFileUPDATE]

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF OBJECT_ID('IMPACT_PROD..HCSReturnFile') IS NOT NULL
DROP TABLE HCSReturnFile

CREATE TABLE [dbo].[HCSReturnFile](
[EventNumber] [varchar](50) NULL,
[ClaimNumber1] [varchar](50) NOT NULL,
[Resolution] [varchar](50) NULL,
[Resolution2] [varchar](50) NULL,
[ProviderType] [varchar](2) NULL,
[Negotiation] [varchar](50) NULL,
[NEGOYESORNO] [varchar](50) NULL,
[ProviderID] [varchar](50) NOT NULL,
[HCSAuthorizationID] [varchar](20) NULL,
[PROLASTNAME] [varchar](20) NULL,
[proFirstName] [varchar](15) NULL,
[ProOffice] [varchar](35) NULL,
[TOTALBILLEDAMT] [varchar](50) NOT NULL,
[SAVINGS] [varchar](50) NOT NULL,
[OONNEGO] [varchar](50) NOT NULL,
[CLM_ATT1] [varchar](50) NULL,
[CLM_ATT2] [varchar](50) NULL,
[CLM_ATT3] [varchar](50) NULL,
[CLM_ATT4] [varchar](50) NULL,
[CLM_ATT5] [varchar](50) NULL,
[NoteData] [varchar](8000) NULL)


INSERT INTO [IMPACT_PROD].[dbo].[HCSReturnFile]
([EventNumber]
,[ClaimNumber1]
,[Resolution]
,[Resolution2]
,[ProviderType]
,[Negotiation]
,[NEGOYESORNO]
,[ProviderID]
,[HCSAuthorizationID]
,[PROLASTNAME]
,[proFirstName]
,[ProOffice]
,[TOTALBILLEDAMT]
,[SAVINGS]
,[OONNEGO]
,[CLM_ATT1]
,[CLM_ATT2]
,[CLM_ATT3]
,[CLM_ATT4]
,[CLM_ATT5]
,[NoteData])
SELECT Distinct
--n.note_sys,
--c.CLM_id1 AS 'ClaimNumber',
e.EVE_id1 AS 'EventNumber',
ClaimNumber1 = '',
--e.EVE_clm As 'EventEventTable',
--c.CLM_elrc AS 'EventClaimTable',
e.eve_resl1 as 'Resolution',
p.EVEP_RESL1 as 'Resolution2',
p.evep_reas as 'ProviderType',
p.evep_nego as 'Negotiation',
--e.EVE_STAT AS 'STATUS',
e.EVE_SW01 AS 'NEGOYESORNO',
ProviderID = '',
e.EVE_EXNO AS 'HCSAuthorizationID',

--p.EVEP_LNAME AS 'PROVIDERLASTNAME',
--p.EVEP_FNAME AS 'PROVIDERFIRSTNAME',
p.EVEP_LNAME AS PROLASTNAME,
p.evep_fname AS proFirstName,
p.evep_offic AS ProOffice,
--c.CLM_EDID AS 'LOCKDATE',
TOTALBILLEDAMT = '',
SAVINGS = '',
OONNEGO = '',
c.CLM_ATT1,
c.CLM_ATT2,
c.CLM_ATT3,
c.CLM_ATT4,
c.CLM_ATT5,
n.NoteData

FROM dbo.EVE e

RIGHT JOIN dbo.clm c
ON e.EVE_id1 = c.clm_id1
RIGHT JOIN dbo.EVEP p
ON e.eve_id1 = p.EVEP_id1
JOIN dbo.notes2 n
ON n.eve_id1 = e.EVE_id1
--JOIN evep p2
--ON p.evep_id1 = p2.evep_id1

Where
e.eve_resl1 = 'CL'and
p.EVEP_RESL1 <> 'NG' and
p.evep_reas <>'FA'--and ---means closes Events
--p2.evep_nego = 'Y' and
--((LTRIM(p.evep_id2) <> '0002' AND p.evep_id2 <> '0001' AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1)
--e.EVE_STAT = 'CL'and
--e.EVE_id1 IN ('00101965','00102080','00102084','00101962','00101963') --and

Order by e.eve_resl1,p.EVEP_RESL1

INSERT INTO [IMPACT_PROD].[dbo].[HCSReturnFile]
([EventNumber]
,[ClaimNumber1]
,[Resolution]
,[Resolution2]
,[ProviderType]
,[Negotiation]
,[NEGOYESORNO]
,[ProviderID]
,[HCSAuthorizationID]
,[PROLASTNAME]
,[proFirstName]
,[ProOffice]
,[TOTALBILLEDAMT]
,[SAVINGS]
,[OONNEGO]
,[CLM_ATT1]
,[CLM_ATT2]
,[CLM_ATT3]
,[CLM_ATT4]
,[CLM_ATT5]
,[NoteData])

SELECT Distinct
--n.note_sys,
--c.CLM_id1 AS 'ClaimNumber',
e.EVE_id1 AS 'EventNumber',
ClaimNumber1 = '',
--e.EVE_clm As 'EventEventTable',
--c.CLM_elrc AS 'EventClaimTable',
e.eve_resl1 as 'Resolution',
p.EVEP_RESL1 as 'Resolution2',
p.evep_reas as 'ProviderType',
p.evep_nego as 'Negotiation',
--e.EVE_STAT AS 'STATUS',
e.EVE_SW01 AS 'NEGOYESORNO',
ProviderID = '',
e.EVE_EXNO AS 'HCSAuthorizationID',

--p.EVEP_LNAME AS 'PROVIDERLASTNAME',
--p.EVEP_FNAME AS 'PROVIDERFIRSTNAME',
p.EVEP_LNAME AS PROLASTNAME,
p.evep_fname AS proFirstName,
p.evep_offic AS ProOffice,
--c.CLM_EDID AS 'LOCKDATE',
TOTALBILLEDAMT = '',
SAVINGS = '',
OONNEGO = '',
c.CLM_ATT1,
c.CLM_ATT2,
c.CLM_ATT3,
c.CLM_ATT4,
c.CLM_ATT5,
n.NoteData

FROM dbo.EVE e

RIGHT JOIN dbo.clm c
ON e.EVE_id1 = c.clm_id1
RIGHT JOIN dbo.EVEP p
ON e.eve_id1 = p.EVEP_id1
JOIN dbo.notes2 n
ON n.eve_id1 = e.EVE_id1
--JOIN evep p2
--ON p.evep_id1 = p2.evep_id1

Where
((e.eve_resl1 = '' and p.evep_reas = 'HO')or (e.eve_resl1 = '' and p.evep_reas = 'PH') or (e.eve_resl1 = '' and p.evep_reas = 'AN'))

Order by e.eve_resl1,p.EVEP_RESL1


--and ---means Open Events will not have claims attached to them. we just need the fields in this report.
--p2.evep_nego = 'Y' and
--((LTRIM(p.evep_id2) <> '0002' AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1)


INSERT INTO [IMPACT_PROD].[dbo].[HCSReturnFile]
([EventNumber]
,[ClaimNumber1]
,[Resolution]
,[Resolution2]
,[ProviderType]
,[Negotiation]
,[NEGOYESORNO]
,[ProviderID]
,[HCSAuthorizationID]
,[PROLASTNAME]
,[proFirstName]
,[ProOffice]
,[TOTALBILLEDAMT]
,[SAVINGS]
,[OONNEGO]
,[CLM_ATT1]
,[CLM_ATT2]
,[CLM_ATT3]
,[CLM_ATT4]
,[CLM_ATT5]
,[NoteData])
SELECT Distinct
c.CLM_elrc AS 'EventNumber',
CASE c.clm_ips
WHEN 'C' THEN c.clm_pclm
ELSE c.clm_id1
END as "claimnumber1", --ClmClaims."CLAIMNUMBER",
--c.CLM_PCLM as "CLAIMNUMBER",
--n.note_sys,
--c.clm_id1,
--e.EVE_clm As 'EventEventTable',
e.eve_resl1 as 'Resolution',
p.EVEP_RESL1 as 'Resolution2',
p.evep_reas as 'ProviderType',
p.evep_nego as 'Negotiation',
--e.EVE_STAT AS 'STATUS',
e.EVE_SW01 AS 'NEGOYESORNO',
c.CLM_5 AS 'ProviderID',
e.EVE_EXNO AS 'HCSAuthorizationID',
--p.EVEP_LNAME AS 'PROVIDERLASTNAME',
--p.EVEP_FNAME AS 'PROVIDERFIRSTNAME',
--p.EVEP_OFFIC AS 'PROVIDEROFFICE',
p.evep_lname AS ProLastName,
p.evep_fname AS proFirstName,
p.evep_offic AS ProOffice,
c.CLM_MCHG AS 'TOTALBILLEDAMT',
c.CLM_SPPO AS 'SAVINGS',
c.CLM_55d AS 'OONNEGO',
c.CLM_ATT1,
c.CLM_ATT2,
c.CLM_ATT3,
c.CLM_ATT4,
c.CLM_ATT5,
n.NoteData

FROM dbo.EVE e
Right Join dbo.clm c
ON e.EVE_id1 = c.clm_elrc
Right join dbo.EVEP p
ON e.eve_id1 = p.EVEP_id1
--JOIN evep p2
--ON p.evep_id1 = p2.evep_id1
JOIN dbo.notes2 n
ON n.eve_id1 = e.EVE_id1

Where
p.EVEP_RESL1 = 'NG'and
clm_adjto = '' ---"NG"This report is going to be changed to the negoitated report the field is going to be "NG"
--e.eve_resl1 = 'NG'and
--p2.evep_nego = 'Y' and
--((LTRIM(p.evep_id2) <> '0002' AND p.evep_id2 <> '0001'AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1)

Order by e.eve_resl1,p.EVEP_RESL1

END

View 3 Replies


ADVERTISEMENT

Analysis :: Order Of Rows In Tabular Table Not In Same Order Data Was Retrieved?

May 19, 2015

I never paid much attention to this before but I noticed this today in a new table I was creating.

For tables defined in the tabular model the table properties have something like SELECT Blah FROM TableName ORDER BY Blah Then in the tabular model the table's data is in the same order it was ordered by in the data source for the table.

I have a date table I setup and I noticed it is NOT respecting the sort order.

I have it sorted by DateID which sorts with the oldest date first and newest date as last row.However, the table that is imported and stored in the data model is not in that order.

I can of course manually sort the rows in BIDS/DataTools, but I find this discrepancy odd.

Would this have negative impacts on the EARLIER function for example if the data rows are not in the order specified?

View 8 Replies View Related

Default Sort Order - Open Table - Select Without Order By

Mar 27, 2008

Hi!

I recently run into a senario when a procedure quiered a table without a order by clause. Luckily it retrived data in the prefered order.

The table returns the data in the same order in SQL Manager "Open Table"

So I started to wonder what deterimins the sort order when there is no order by clause ?

I researched this for a bit but found no straight answers. My table has no PK, but an identiy column.

Peace.

/P

View 5 Replies View Related

Time Taking Table

Oct 12, 2007

Dear Experts,
i've one table named table11. in this perticular table, i've 30 columns and 40,000 rows of data.
this table is taking 35 sec for select * from table11.

defnetly it will take more time if i used this in some places like procedures and functions or views like that.

where is the problem? generally it takes that much of time or is there any problem?

guidence please.....

Vinod
Even you learn 1%, Learn it with 100% confidence.

View 4 Replies View Related

Taking EAV Create Dimension Table

Sep 13, 2006

I have a result set as follow

Jobid, ClassId, ClassValue
1 GroupName Joes Auto
1 EffDate 1/1/6
1 Userid XYZ1234
....
2 GroupName Sams Eatery
2 EffDate 2/1/6
2 UserID ABC0987

ETC...

I need

Jobid GroupName EffDate Userid
1 Joes Auto 1/1/6 xyz1234
2 Sams Eatery 2/1/6 abc0987

I can manipulate this in a pivot table for reporting however I need this to be a table for reporting by filterable searchable information. What can I do short of defining each field with case logic, or union queries.

View 1 Replies View Related

Table Update Process Is Taking Too Much Time

Mar 9, 2008



hi,


I'm using a OLE DB COMMAND component to perform an update (SQL statement) but the procces takes about 9 hours, so I changed it to a stored procedure but it was the same, I need to update about a a million of rows and the package is very simple.

How can I improve the time, Can I use another component or startegy?

thanks

View 3 Replies View Related

Taking Time For Retrieve Data From Temperary Table

Feb 11, 2008

View 1 Replies View Related

T-SQL (SS2K8) :: Table With 3 Million Plus Records Taking Half A Minute?

Aug 6, 2015

I have a table that I need to do some computations on all the data but first I need to remove the duplicate records and insert the results into a destination table. Here's the example below. My table has 3.1 million rows. I have tried using the DISTINCT and the GROUP BY but both ways to select the data takes about half a minute to run. I'm wondering if there is a way to increase performance. Users are ok with this time since the process runs overnight but improving it won't hurt. I do have a clustered index on these fields but that doesn't seem to improve any.

SELECTDateYear ,
DateMonth ,
Nbr ,
Nbr1 ,
Nbr2 ,
Datafield1 ,
Datafield2,

[code].....

View 7 Replies View Related

Select Into Statement Without Taking Auto Increment Of ID Column To The New Table

Mar 7, 2011

Due to localization I have the need to make child tables, where there is a composite Primary Key, between the Id column and the LanguageSign column. On the parent table the Id column is Identity column with auto increment.

The problem is that during the select into query to copy columns from parent to child, this auto increment behaviour of the parent-Id is copied to the child-Id. However I do not want that, because the same Id will be used by different LanguageSign entries

Is there a way to use 'select into' without copying the auto increment, or is my only option to make a whole new column without auto increment on the child and copy the records?
 
btw I have used this statement

SET
IDENTITY_INSERT MyTable

ON , so that inserting into the Id column is possible. I can see however that this does not take away the auto increment...

View 4 Replies View Related

Help: Database Table Taking 9GB Of Disk Space But Only Contains 50Mb Data.

Dec 11, 2007

Disk space is increasing at an alarming rate (about 500MB a day). Shrink of database seems to have no effect. It is a queueing table so data is inserted then a few minutes later it gets processed & deleted.

Here is info about the problem:

sp_spaceused ImporterModuleQueue

name rows reserved data index_size unused
------------------- ----------- ------------------ ------------------ ------------------ ------------------
ImporterModuleQueue 30 9469432 KB 9468280 KB 32 KB 1120 KB

This is about 9 GB


select sum(len(QueueContent)) from ImporterModuleQueue

49744918

select sum(len(QueueErrors)) from ImporterModuleQueue

43529

This is about 50 Mb


CREATE TABLE [dbo].[ImporterModuleQueue](
[ImporterModuleQueueId] [int] IDENTITY(1,1) NOT NULL,
[ImporterModuleId] [int] NOT NULL,
[StartedDateTime] [datetime] NULL,
[FinishedDateTime] [datetime] NULL,
[QueueContent] [varchar](max) NOT NULL,
[CreatedDateTime] [datetime] NOT NULL,
[QueueErrors] [varchar](max) NULL,
[QueueSourceId] [int] NOT NULL,
[QueueStatusId] [int] NOT NULL CONSTRAINT [DF_ImporterModuleQueue_IsProcessed] DEFAULT ((0)),
CONSTRAINT [PK_ImporterProcessQueue] PRIMARY KEY NONCLUSTERED
(
[ImporterModuleQueueId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


--

dbcc opentran

No active open transactions.

--

DBCC SHOWCONTIG scanning 'ImporterModuleQueue' table...
Table: 'ImporterModuleQueue' (2030070418); index ID: 0, database ID: 5
TABLE level scan performed.
- Pages Scanned................................: 14
- Extents Scanned..............................: 10
- Extent Switches..............................: 9
- Avg. Pages per Extent........................: 1.4
- Scan Density [Best Count:Actual Count].......: 20.00% [2:10]
- Extent Scan Fragmentation ...................: 80.00%
- Avg. Bytes Free per Page.....................: 5714.1
- Avg. Page Density (full).....................: 29.40%

View 4 Replies View Related

Add Calculated Field In Order Table Based On Price Column In Product Table

Nov 18, 2014

I have 2 tables: Order(ID, Quantity) and Product(ID,Name, Price) and I want to add a calculated field in Order table based on the price column in the Product table. How do i do that?

this query returns the values i want in the table.

select a.quantity * b.price
from tblCustomerPurchases as a
join tblProduct as b
on a.ID=b.ID

View 17 Replies View Related

Table Order

Jun 8, 1999

I have a database with 200+ tables. How can I get table order (query) from the system tables so that I know which table I should insert data first.

Thanks,

View 2 Replies View Related

FROM Table Order?

Oct 23, 2007

I noticed that some queries against an mssql db require the tables in the FROM part of the statement to be in a particular order. Does anyone know why?

For example SELECT * FROM table1, table2, table3 WHERE <blah>

May throw an error (Unknown table table3 [I can't remember the exact verbiage of the error]), while simply rearranging the table order to:

SELECT * FROM table3, table1, table2 WHERE <blah> will work.

It seems like the error has something to do with how mssql handles the joins of the tables, but I can't seem to find any documentation about it.

View 2 Replies View Related

How To Order This Table.

Mar 19, 2007

I have a table

merchant contractbr date
a 2333 1/1/2005
a A34 3/12/2006
a R78 2/1/2005
..
b
b
b
c
c
c
.....

different merchant has different number of contracts.
I want to order the contracts for merchants according to the date.
the result table should look like:

merchant contractbr date order
a 2333 1/1/2005 1
a R78 2/1/2005 2
a A34 3/12/2006 3
..
b 1
b 2
b 3
c 1
c 2
c 3
c 4
c 5
.....

Thanks

View 5 Replies View Related

Regarding Table Order

Dec 16, 2005

Greetings,I have an application that need to get all the userdefined child tables first before their parents.I wrote a query, given in this newsgroup only, as belowSELECT o.nameFROM sysobjects oWHERE o.type='U'ORDER BY case WHEN exists ( SELECT *FROM sysforeignkeys fWHERE o.id = f.fkeyid )THEN 1ELSE 0end, o.namegoWhen i try to truncate the first table of the list, it still tells methat tha table is being referenced by foreign key in another table. Mymain job is to truncate all the user defined tables before loading datainto them.Is there something wrong in the query? Or if someone can tell me abetter approach.Any help will be appreciated.TIA

View 5 Replies View Related

Table Order By Clause

Mar 23, 2006

When I say to sort on a datetime field on descending order, the date is sorted. However, the time difference is not reflected in the results.
Any way, we can fix it.
i.e. If I have two records with the same dates but different times, the sorting order is not considering the time.

View 1 Replies View Related

Order Of Insert Row In A Table

Jun 13, 2000

Without inserting an additional column with a timestamp or adding an IDENTITY column, can you tell which row was inserted first in a table?

Angel

View 2 Replies View Related

Replication: Table Order

May 22, 2002

SQL Trasnsactional Replication.

I've set up a transactional replication, but I need to specify in which order the tables are to be replicated (tables with foreign keys last).
How/where do set table order ?

/Carl

View 1 Replies View Related

How To Know The Order Of Entries In A Table

Jul 5, 2007

For example some data has entered into a table in a random manner i.e the pk filed value is not in a serial fashion.Is there any table or index that holds the entries of rows into a particular table as entered .

i.e
'some_table' has data like this

3,entry3
2,entry2
4,entry4
1,entry1

I want some DB table or Index that holds data like this about above 'some_table'

row_id .... .... ....
1
2
3
4

here 1 refers to entry of the first column in 'some_table' i.e 3,entry3
and so on...

View 2 Replies View Related

SSMS Table Order

Apr 14, 2015

Is there a way to show tables in alphabetical order when you expand the table node of a database from inside SSMS?

View 3 Replies View Related

How To Re-order The ID Column Of A Table?

Oct 5, 2007

I have a table that I want to re-order the ID column. The ID are not in order now due to some insertion and deletion. What are the steps to re-order the ID column?

Thanks in advance.

View 6 Replies View Related

How To Use Order By In Pivot Table ?

Mar 10, 2008

heed help
i have a PROCEDURE that generate PIVOT table
how to use ORDER BY

in this part
how to do this ?
ORDER BY unit desc, Fname



Code Snippet
SELECT p.ID,p.new_unit,p.mhlka_id,p.mhlka,
p.[1] , p.[2],p.[3], p.[4], p.[5], p.[6], p.[7], p.[8], p.[9], p.[10], p.[11],
p.[12], p.[13], p.[14], p.[15], p.[16], p.[17], p.[18], p.[19], p.[20], p.[21],
p.[22], p.[23], p.[24], p.[25], p.[26], p.[27], p.[28], p.[29], p.[30]
FROM (

SELECT ID,new_unit,mhlka_id,mhlka,
DATEPART(DAY, Date) AS theDay,
ShiftID
FROM v_Employee
WHERE Date >= @BaseDate
AND Date < DATEADD(MONTH, 1, @BaseDate)

ORDER BY unit desc, Fname

) AS y
PIVOT (
min(y.ShiftID) FOR y.theDay IN ([1], [2], [3], [4], [5], [6], [7],[8] , [9], [10], [11],
[12], [13], [14], [15], [16], [17], [18], [19], [20], [21],
[22], [23], [24], [25], [26], [27], [28], [29], [30])
) AS p
END




the all code




DECLARE @Employee TABLE (ID INT, Date SMALLDATETIME, ShiftID TINYINT)





DECLARE @WantedDate SMALLDATETIME, -- Should be a parameter for SP

@BaseDate SMALLDATETIME,

@NumDays TINYINT

SELECT @WantedDate = '20080401', -- User supplied parameter value

@BaseDate = DATEADD(MONTH, DATEDIFF(MONTH, '19000101', @WantedDate), '19000101'),

@NumDays = DATEDIFF(DAY, @BaseDate, DATEADD(MONTH, 1, @BaseDate))

IF @NumDays = 28

BEGIN



SELECT p.ID,

p.[1], p.[2], p.[3], p.[4], p.[5], p.[6], p.[7], p.[8], p.[9], p.[10], p.[11],

p.[12], p.[13], p.[14], p.[15], p.[16], p.[17], p.[18], p.[19], p.[20], p.[21],

p.[22], p.[23], p.[24], p.[25], p.[26], p.[27], p.[28]

FROM (

SELECT ID,

DATEPART(DAY, Date) AS theDay,

ShiftID

FROM v_Employee

WHERE Date >= @BaseDate

AND Date < DATEADD(MONTH, 1, @BaseDate)

) AS y

PIVOT (

COUNT(y.ShiftID) FOR y.theDay IN ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11],

[12], [13], [14], [15], [16], [17], [18], [19], [20], [21],

[22], [23], [24], [25], [26], [27], [28])

) AS p

END

ELSE IF @Numdays = 30

BEGIN



SELECT p.ID,p.new_unit,p.mhlka_id,p.mhlka,

p.[1] , p.[2],p.[3], p.[4], p.[5], p.[6], p.[7], p.[8], p.[9], p.[10], p.[11],

p.[12], p.[13], p.[14], p.[15], p.[16], p.[17], p.[18], p.[19], p.[20], p.[21],

p.[22], p.[23], p.[24], p.[25], p.[26], p.[27], p.[28], p.[29], p.[30]

FROM (



SELECT ID,new_unit,mhlka_id,mhlka,

DATEPART(DAY, Date) AS theDay,

ShiftID

FROM v_Employee

WHERE Date >= @BaseDate

AND Date < DATEADD(MONTH, 1, @BaseDate)

) AS y

PIVOT (

min(y.ShiftID) FOR y.theDay IN ([1], [2], [3], [4], [5], [6], [7],[8] , [9], [10], [11],

[12], [13], [14], [15], [16], [17], [18], [19], [20], [21],

[22], [23], [24], [25], [26], [27], [28], [29], [30])

) AS p

END

View 3 Replies View Related

Table Execution Order

Nov 14, 2007

I have nested lists and I want to set a global value in my custom code AFTER a specific table footer row. Does anybody know in what order the table elements are rendered? I have tried adding my piece of code into a group value, the hidden property, the color property, and sending it as a parameter to a subreport, but it still sets that variable first before rendering the table footer row that I want to display before I set that variable. I have been pulling my hair out trying to do this one! Help!

BJ

View 1 Replies View Related

Rearrange Field Order Of A Table

Apr 27, 2000

Hi,

How can I rearrange the fields in a table in SQL 7? If it is possible, will the existing data be lost?


Thank you for any help.

View 5 Replies View Related

ORDER BY (field In Foreign Table)

Apr 4, 2008

Newbie question. Can someone show me an SQL statement that sorts the results of a query by a field in a different table?

CREATE TABLE `Table1`
(
`table1_id` INTEGER AUTO_INCREMENT ,
`table1_name` VARCHAR(255),
PRIMARY KEY (`table1_id`)
)

CREATE TABLE `Table2`
(
`table2_id` INTEGER AUTO_INCREMENT ,
`table2_name` VARCHAR(255),
`table2_table1` INTEGER,
PRIMARY KEY (`table2_id`)
)

ALTER TABLE `Table2` ADD FOREIGN KEY (`table2_table1`) REFERENCES `Table1`(`table1_id`);

What I'd like is something like:

SELECT * FROM Table2 ORDER BY "Table1(table2_table1).tabel1_name",table2_name

It's the section in double quotes that I can't figure out how to compose.

As an example, if Table 1 has
1, A
2, B
3, C

and Table 2 has
1, a, 2
2, b, 1
3, c, 2

then I'd like the sort to return
2, b, 1
1, a, 2
3, c, 2


TIA,

Stephen

View 2 Replies View Related

How To Keep Original Order When Querying A Table?

Sep 10, 2004

Hello, everyone:

I have a table like:

ColName
b
b
b
d
d
d
a
a
c
c
c

I use DISTINCT to filter duplicated row. I want to get the return by original order like:
b
d
a
c

However, SQL Server re-order it if using DISTINCT and return like:
a
b
c
d

Can any one have the idea to handle that? Thanks

ZYT

View 4 Replies View Related

Determine Table Load Order

Nov 23, 2004

Does anyone have a script that analyzes primary and foreign key relationships of tables and produces a suggested load order based upon dependancies?

Thanks,

Fred.

View 4 Replies View Related

Pivot Table Month Name Order?

Dec 2, 2013

how to order by month name query returns Dec13,Mar14,Jan14,Nov13 .. etc but i want to Nov13,Dec13,Jan14,Mar14 ... etc

declare @cols as varchar(max),
@query as varchar(max)
set @cols =STUFF((select ','+QUOTENAME(tb3.month) FROM
( select distinct (DATENAME(MONTH,dtDate)+''+CONVERT(varchar(5),YEAR(dtDate)) ) as month
from tableA) tb3
FOR XML PATH(''), TYPE ).value('.','NVARCHAR(MAX)'),1,1,'')
set @query ='SELECT '+@cols +' from (SELECT DATENAME(MONTH,dtDate) + CONVERT(varchar(5),YEAR(dtDate)) as month,Price FROM tableA ) tb
pivot ( sum(Price) for monthin('+@Cols+')) p
'exec(@query)

View 6 Replies View Related

Keep Order Of Left Table After Join

May 20, 2014

I have an problem with the order of the results after a join.

My first query works fine and the order of field Name ist correct.

Select *
FROM
(SELECT * FROM
dtree A1
WHERE
A1.Subtype=31356
AND
A1.DataID IN
(select DataID from dtreeancestors where AncestorID=9940974)) t

When I do a join the order of the left table changes

Select *
FROM
(SELECT * FROM
dtree A1
WHERE
A1.Subtype=31356
AND
A1.DataID IN
(select DataID from dtreeancestors where AncestorID=9940974)) t, llattrdata A4
WHERE
t.DataID = A4.ID

How can I do a join and keep the order of the left table?

View 4 Replies View Related

Table Order In Clustered Index?

Feb 29, 2008

I have a table "Client" that has two columns: "ClientID" and "ProductID". I created on clustered index on ClientID and when I opened the table in the management studio, I saw the table was in the order of ClientID.

Then I added another non-clustered index on ProductID. When I open the table again, it is in the order of ProductID. Shouldn't the table always be in the order of clustered index? Non-clustered index should be a structure outside of the table itself? Did I do anything wrong?

Thanks for any hint.

View 17 Replies View Related

Table Order When Inserting Data

Jul 23, 2005

I have to import data into a empty database, that has many tables.some tables have to be inserted first than others due to the foreignkeys.How do I find out the order of the tables that I have to insert datainto?Thanks in advance!Sam

View 6 Replies View Related

Changing Column Order In A Table

Jul 20, 2005

This subject has been posted several times, but I haven't seen a goodanswer.Problem:I want to change the order of the columns in a table using T-SQL only.Explanation:After running your code, I want to see the following table...CREATE TABLE [dbo].[TableName] ([First_Column] [int] NULL ,[Second_Column] [varchar] (20) NULL) ON [PRIMARY]look like this...CREATE TABLE [dbo].[TableName] ([Second_Column] [varchar] (20) NULL ,[First_Column] [int] NULL) ON [PRIMARY]Limitations:Don't post if your post would fall in the following categories:1. If you don't think it can be done2. If you think Enterprise Manager is the only way to do this3. If you think I should just change the order of my Selectstatements4. If you want to state that order column doesn't matter in arelational database5. If you want to ask me why I want to do thisWish:Hopefully the answer WON'T involve creating a brand new table, movingthe data from old to new, dropping the old table, then renaming thenew table to the old name. Yes, I can do that. The table I'm workingwith is extremely huge -- I don't want to do the data juggling.Thanks in advance!

View 2 Replies View Related

Alter Table And Column Order

Jul 20, 2005

Is it possible to add a column to a table using the "alter table"statement and specify where in the sequence of columns the new columnsits. If not is there any way to alter the order of columns using TSQLrather than Enterprise Manager / Design Table.TIALaurence Breeze

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved