Avatar of satmisha
satmisha
Flag for India asked on

Merge Rows in Sql Server

Hi Expert,

I have provided sample table in sql server :

ID      Name      Dep                Add
1      A               N                A-1
1      B               K                A-1
1      C               M                A-1
2      D               Z                A-2
2      E               O                A-2

Note: Above rows can be dynamic, it is not static like ID = 1 can have 3 rows as stated above or it could have more  or less than 3 as well.

Expected output is:
ID      Name1      Name2      Name3      Dep1      Dep2      Dep3      Add
1      A                  B                 C                N                K                M              A-1
2      D                  E               NULL        Z                O              NULL        A-2


Hopefully looking forward to hearing from you.
Microsoft SQL Server 2005Microsoft SQL Server

Avatar of undefined
Last Comment
satmisha

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
satmisha

ASKER
Thanks for your reply..
seems like it is not working as it is expecting columns as int whereas in above stated example it is varchar...
Guy Hengel [angelIII / a3]

I did not test the function, the key for you is to use "othercolumns" (@OtherCols) argument ...
satmisha

ASKER
Thanks angelIII,

Apologies for late reply

Above stated didn't work.

But I got the solution by making sql function with special character saparated column.
Your help has saved me hundreds of hours of internet surfing.
fblack61
satmisha

ASKER
request to pls close this question as provided answer was not appropiate.. n I am unable to see any option to close by my own...

Thanks