December 11, 2019 at 9:56 am
I have a table
id pid aid vid
8 1301 2 10
9 1301 2 11
10 1301 3 12
11 1302 7 52
when i pass pid as 1301 i wish to get result as
aid vid
2 10, 11
3 12
December 11, 2019 at 10:32 am
i guess pivot wont work. i want multiple columns to convert to row.
December 11, 2019 at 11:14 am
OK, so the requirement has changed a little. You now need to concatenate the values into a string rather than having each as a separate column in the same row. If you are using SQL Server 2017 or later, you can use the STRING_AGG aggregate function, otherwise I recommend that you try the FOR XML technique described in this article.
John
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply