How to combine two or more rows corresponding to same id to remove duplicate rows
step 1 : Create Table #EscrowNo(rootId int,reference nvarchar(50))
steo2 : insert into #EscrowNo (select distinct RootId# ,
STUFF((Select ','+ReferenceNumber
from [pfm].[Contact] pfmEscrow)
where pfmEscrow.RootId#=pfmEscrow2.RootId#
FOR XML PATH('')),1,1,'') from [pfm].[Contact] pfmEscrow2
step 3 : select * from #EscrowNo
Result:
You have merged all the rows corresponding to similar id in one row
step 1 : Create Table #EscrowNo(rootId int,reference nvarchar(50))
steo2 : insert into #EscrowNo (select distinct RootId# ,
STUFF((Select ','+ReferenceNumber
from [pfm].[Contact] pfmEscrow)
where pfmEscrow.RootId#=pfmEscrow2.RootId#
FOR XML PATH('')),1,1,'') from [pfm].[Contact] pfmEscrow2
step 3 : select * from #EscrowNo
Result:
You have merged all the rows corresponding to similar id in one row
No comments:
Post a Comment