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.
Hi,I'm trying to create a query that will result in distinct values in column 1 and concatenate all of the possible column 2 values where there is a many to one relationship. Any ideas? Table: POLIST PONum ReqNumPO1010 1190PO1010 1191PO1011 1192PO1012 1193PO1013 1194 5 records Query Result PONum ReqNumPO1010 1190, 1191PO1011 1192PO1012 1193PO1013 1194 4 records
http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tablesis also helpful.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-08-29 : 01:46:15
if its sql 2005, you can do like this
SELECT t.PONum,LEFT(nl.numlist,LEN(nl.numlist)-1)FROM(SELECT DISTINCT PONum FROM POList) tCROSS APPLY(SELECT CAST(ReqNum AS varchar(10)) + ',' AS [text()] FROM POList WHERE PONum=t.PONum FOR XML PATH(''))nl(numlist)