• Question

  • Hi,

    Please provide me the query to get output from the below table.


    1 abc Project1
    1 def Project1
    2 pqr Project2
    2 xyz Project2
    1 ghi Project1
    3 mno Project3

    Out put: 

    1 Project1 abc,def,ghi
    2 Project2 pqr,xyz
    3 Project3 mno

    • Moved by CoolDadTx Tuesday, October 6, 2020 2:46 PM SQL related
    Tuesday, October 6, 2020 5:57 AM

All replies

  • The simple way is to create a stored procedure:

    1) create a table-valued-variable @tvv with 3 columns

    2) do "insert...select distinct field1, field3, '' into @tvv from table"

    3) create cursor to loop the table to update the second column of @tvv with field2

    4) return the @tvv

    Since these are all simple SQL statements, maybe you can try doing it yourself.

    Tuesday, October 6, 2020 6:32 AM
  • Hi,

    Thank you for posting here.

    Since this thread is related to T-Sql, so So you can also ask your questions in Microsoft Q&A.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 6, 2020 9:30 AM