May 1, 2018 at 3:15 am
Hi there
I want to take a column of values and transpose them into a comma delimited list.
This is a one off task and i want to avoid using table valued functions.
My example data is
IF OBJECT_ID(N'TempDB.dbo.#PartyDetail') IS NOT NULL DROP TABLE #PartyDetail
Create table #PartyDetail
( PartyID int)
Insert into #PartyDetail (PartyID)
select 56814672 as PartyID
union
select 56825090 as PartyID
union
select 56817184 as PartyID
union
select 56810267 as PartyID
union
select 56825587 as PartyID
union
select 56812603 as PartyID
union
select 56835172 as PartyID
union
select 56838276 as PartyID
union
select 56824266 as PartyID
I want to be able to output the following
'56810267','56812603','56814672','56817184','56824266', '56825090','56825587','56835172','56838276'
Please tell me how I can do this?
Thanks
May 1, 2018 at 5:10 am
BrainDonor - Tuesday, May 1, 2018 4:42 AMI have an example similar to that here.
Hi Steve
Brilliant that worked for me very well.
I added the following to my script
declare @PartyIDList2varchar(max)
SELECT @PartyIDList2 = STUFF((SELECT ', ' + cast(partyid as varchar(20))
FROM #HoldingDetail
ORDER BY partyid
FOR XML PATH('')), 1, 2, '');
Thank you very much for your help on this
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply