revering columns into rows in a specific way

  • 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

     

    • This topic was modified 4 years, 11 months ago by  sivaay1223.
  • Please will you show us what you've already tried?  Have you looked into PIVOT?

    John

  • i guess pivot wont work. i want multiple columns to convert to row.

  • 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