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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concat Question

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2009-02-04 : 10:48:38
Hi Guys
I have a table/view with the following data:
ReceiptID, SKU, ProductDescription
11277922, SAHAE410208, Laura Lees Ruffle Edge Dress
11277922, IBIUN162836, Braza Seam Free Invisible Bandeau
11277922, SAHAE447830, Happie Loves It Stripe Cotton Dress
11277922, QAHAE339840, Peoples Market Jersey Dress

Is it possible in SQL to produce a query that returns all details in one row?
Eg:
127792, “SAHAE410208 Laura Lees Ruffle Edge Dress”,” IBIUN162836 Braza Seam Free Invisible Bandeau”,” SAHAE447830 Happie Loves It Stripe Cotton Dress”,” QAHAE339840 Peoples Market Jersey Dress”

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-04 : 10:55:00
yup its possible

SELECT DISTINCT t.ReceiptID,STUFF((SELECT ',' + '"'+ SKU + '"' + ',' + '"'+ ProductDescription + '"' FROM Table WHERE ReceiptID=t.ReceiptID FOR XML PATH('')),1,1,'') AS Value
FROM Table t
Go to Top of Page

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2009-02-04 : 11:06:32
Thank you as always visakh
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-02-04 : 11:14:37
why the heck are you trying to do that? imagine if your table has 10million rows. just trying to understand the reason why.
Go to Top of Page

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2009-02-04 : 11:22:36
Its just for reporting purposes. There won't be that many rows as the data is only for 1 day.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-04 : 12:10:01
quote:
Originally posted by rcr69er

Thank you as always visakh


you're welcome as always
Go to Top of Page
   

- Advertisement -