Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Combine the data (Multiple rows data to single row)

$
0
0

Hi all,

I don't know how to explain this issue , so decided to write in multiple steps,i tried in every way that i know but no result , i hope below explanation will be enough, if you need any other info please let me know ,Any help will be appreciated!!!  

I have a table ( testdata ) with following fields and data

ID     ID1    ID2   Name

1 2         3        A

1       2         3       B 

1       2         3      C

4       5         6       D

4      5         6        E

4       5          6       F 

I wrote a query as shown below

select id,id1,id2,(
select '' + name from [dbo].[testdata]
for xml path  ('') Fulname
)
from [dbo].[testdata]
group by id1,id2,id

result set i got is  : 

ID    ID1     ID2           Fullname 

1        2          3              ABCDEF

4        5          6              ABCDEF

but  i am looking for a result set as shown below 

ID      ID1       ID2          FullName

1        2             3               ABC

4       5             6               DEF


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>