Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Can someone help me with this? I want to collect the au_lname cells and put them together when having the same state. I will use the solution on another db but used pubs to get help easier.BRMarkusThis is how I want it to look like:state au_lnameCA White, Green, Carson...IN DeFranceKS SmithFrom the result of this query:USE pubsSELECT au.state, au.au_lnameFROM authors auORDER BY state
spirit1
Cybernetic Yak Master
11752 Posts
Posted - 2005-10-27 : 07:42:01
use a function for this:
CREATE FUNCTION dbo.LastNames( @state varchar(2)) RETURNS varchar(8000)AS BEGIN declare @List varchar(8000) SELECT @List = COALESCE(@List + ', ', '') + au_lname FROM authors WHERE state = @state return @ListENDgo select state, dbo.LastNames(state)FROM authors group by stateorder by stategodrop function dbo.LastNames
Maddy, you could simply post this line from your link, instead of posting the link:"Yeah, yeah, yeah, let's get this out of the way right from the start: Don't concatenate rows into delimited strings in SQL Server. Do it client side."Help us help YOU!Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx*need more coffee*SELECT * FROM Users WHERE CLUE > 0(0 row(s) affected)
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-10-28 : 07:36:33
>>"Yeah, yeah, yeah, let's get this out of the way right from the start: Don't concatenate rows into delimited strings in SQL Server. Do it client side."Thats good idea Don MadhivananFailing to plan is Planning to fail