Here's what I'm trying to do. I know how to do it with a temp table and/or
cursor, but was wondering if anyone else knows a more elegant way...
This is about taking a list of parts for an electronic assembly and
reformatting it for output on a report.
Here's an example dataset:
Partnumber Designator
--------------------------------------
Cap1U0 C1
Cap1U0 C2
Cap1U0 C3
Cap1U0 C6
Cap2U2 C4
Cap2U2 C5
And here's now I'd like it to come out:
Partnumber Designators
--------------------------------------------------------------------
Cap1U0 C1, C2, C3, C6
Cap2U2 C4, C5
Sort of like a pivot table, but instead of the rows coming out in separate
columns, I want all the (varchar) values in the second column concatenated
into *one* column. Basically like "group by" with "sum()" but summing text
instead of numbers :^)
Anyone got any clever ideas on this one?
Thanks!
Eric Law
Divesified Technologies, Inc.
PS This is on SQL server 2000 SP4 if it matters.
Aaron Bertrand [SQL Server MVP] - 21 Jul 2008 20:24 GMT
http://www.projectdmx.com/tsql/rowconcatenate.aspx
On 7/21/08 3:17 PM, in article umxFyZ26IHA.5440@TK2MSFTNGP02.phx.gbl, "EL"
<nospam@here.com> wrote:
> Here's what I'm trying to do. I know how to do it with a temp table and/or
> cursor, but was wondering if anyone else knows a more elegant way...
[quoted text clipped - 31 lines]
>
> PS This is on SQL server 2000 SP4 if it matters.
Plamen Ratchev - 21 Jul 2008 20:26 GMT
A few ideas here:
http://www.projectdmx.com/tsql/rowconcatenate.aspx
Note the methods with CTE, ROW_NUMBER and FOR XML PATH will not work as they
are SQL Server 2005 specific.
HTH,
Plamen Ratchev
http://www.SQLStudio.com
ML - 21 Jul 2008 20:28 GMT
See http://www.projectdmx.com:80/tsql/rowconcatenate.aspx or google
"aggregate concatenation".
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
steve dassin - 22 Jul 2008 01:51 GMT
> See http://www.projectdmx.com:80/tsql/rowconcatenate.aspx or google
> "aggregate concatenation".
I know, you were multi-tasking and just happened to forget to mention Rac.
Just a gentle reminder :)