Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set based was to concat strings from n children
Message
 
 
To
28/06/2012 17:44:11
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01547167
Message ID:
01547169
Views:
39
>Trying to avoid cursors and procedural code in tsql
>
>I have a table derived from an SSIS feed that has 1 - n rows that are related, based on symbol, eff_date. If there are more than 1, I want to concatenate the values in a varchar column into the first row
>
>1000 rows, may have 200 rows belonging to 60 sets of 2-4 members
>
>First row of set and any row that has no set has a Seq_num = 1 ( also have a column fgkey int which acts as a key for a set so can use that instead of symbol, eff_date to find rows belong to a set. Singleton rows have no fgkey )
>
>I also have a bit column which I want to be 1 in the first row if any of the rows in the set have a 1
>
>So
>symbol eff_date terms price_sens seq_num
>MSFT 20120601 'string1' 0 1
>MSFT 20120601 'string2' 1 2
>MSFT 20120601 'string3' 0 3
>
>would become
>
>MSFT 20120601 'string1 , string2 , string3' 1
>MSFT 20120601 'string2' 1 -- ( this can stay as it is)
>MSFT 20120601 'string3' 0 -- ( this can stay as it is)
>
>Basically it would be an aggregate function but on strings instead of adding numbers.
>
>If a sum of a bit column would work for finding if the total > 0 I can work that part out.
>
>Looking for some set-based command or magic that would concat the strings
>
>TIA

Read these blogs

MSDN thread about concatenating rows

Making a list and checking it twice
Concatenating Rows - Part 1
Concatenating Rows - Part 2
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform