April 2, 2008 at 12:10 pm
I have a table that contains notes in separate rows with a column indicating when the note was added.
Create table Fred (
account int
,created datetime
,note varchar(max)
)
The result that I want would have the concatenated created and note aggregated into a single row for each account. I can get the single column note to aggregate correctly, but I need the notes to be ordered by created descending within the aggregation.
I have tried TVF's and subqueries to order the rows before they were aggregated, but no luck there (can't use order by in a subquery or TVF). Also, tried to create an aggregation that takes 2 parameters as an input, didn't like that either.
Any ideas?
Thanks for your help.
April 3, 2008 at 1:01 pm
Rich (4/2/2008)
(can't use order by in a subquery or TVF).
From BOL: "...unless TOP is also specified."
Use [font="System"]TOP X[/font] where [font="System"]X[/font] is some number greater than the number of rows you are returning.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply