tsql - T-SQL - how to get around the order by restriction in CTEs -


I have the following CTE, its purpose is to provide unique month / year pairs. Later code will use CTE to create a concatenated string list of months / year pairs

  ;. As with tblStoredWillsInPeriod (Separate Kctc.GetMonthAndYearString Select (DateWillReceived) from Kctc.StoredWills Where DateWillReceived Months '2010/01/01' and DateWillReceived by '2010/03/31' order)  

I have not shown the implimentation of the GetMonthAndYearString function as this is a minor thing.

EDIT: As requested by Martin, the surrounding code is here:

  as announced above @PivotColumnHeaders nvarchar (MAX) --CTE announcement - - Select @PivotColumnHeaders = COALESCE (@PivotColumnHeaders + ', [' + Month + '],' ['+ + + Month +']) with tblStoredWillsInPeriod selection @PivotColumnHeaders  

Unfortunately From, it seems T-SQL is always one step forward. When I run this code, it tells me that I do not have permission to use the command in CET unless I use the top (or whatever I do for XML). If I use the top, then it tells me that I can not use it separately with Yes, T-SQL has all the answers.

Can someone think of solving this problem which is rather quick to reduce my wrist? I understand that death due to blood loss can be astonishingly strange, and there may be time limits for me to meet.

Thank you for your help.

David

is this work

  Announcement @PivotColumnHeadersVARCHAR (Max) ;? Select DateWillReceived Unions with StoredWills (Select GETDATE () as' All Select '2010-03-14 11: 48: 07.580 Union Select All' 2010-03-12 11: 48: 07.580 Union Select All Where as the month from StoredWills as '102010-12-12 11: 48: 07.580 '), as tblStoredWillsInPeriod (MMMYYYY, DatePart (year, DateWillReceived) year, DatePart (Month, DateWillReceived) DateWillReceived - Select 'DISTINCT STUFF (' 'rights (change (VARCHAR, DateWillReceived, 106), 8), 4, 1,) between' 2010-01-01 'and' 2010-03-31 ') @PivotColumnHeaders = COALESCE (@PivotColumnHeaders + ', [' + MMMYYYY + ']', '[' + MMMYYYY + ']') tblStored From WillsInPeriod order year, month  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -