Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group by result in a string...
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01462361
Message ID:
01462365
Views:
59
This message has been marked as the solution to the initial question of the thread.
>I need to report in one string a list of value from a group by.
>Ex:
> SELECT Sort_Plan_Number
> FROM dbo.StagingRollup
> WHERE Valid_Status = -3300
> GROUP BY Sort_Plan_Number
>
>I can use this select in a cursor and then fetch it but I think with SQL 2008 there is a better way.
>Anyone know this one?
DECLARE @test varchar(max)
SELECT @test = ISNULL(@test+',','')+CAST(Sort_Plan_Number as varchar(200))
       FROM dbo.StagingRollup 
WHERE Valid_Status = -3300 
GROUP BY Sort_Plan_Number

SELECT @Test
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform