Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Worse than crosstab...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EL - 21 Jul 2008 20:17 GMT
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 :)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.