Hi, please find the below sample data and expected result
Declare @table table(Name varchar(200),Zipcode varchar(10),State varchar(10),City varchar(50))
Declare @ExpectedOutput table(Zipcode varchar(10),State varchar(10),City varchar(50),Name varchar(max))
insert into @table(Zipcode,Name,State,City)
select 1000 as zip, 'Test1' as store,'NY' as state,'New york' as City union all
select 1000 as zip, 'Test2' as store,'NY' as state,'New york' as City union all
select 1000 as zip, 'Test3' as store,'NY' as state,'New york' as City union all
select 1000 as zip, 'Test4' as store,'NY' as state,'New york' as City union all
select 1001 as zip, 'Test5' as store,'NY' as state,'Buffalo' as City union all
select 1001 as zip, 'Test6' as store,'NY' as state,'Buffalo' as City union all
select 1001 as zip, 'Test7' as store,'NY' as state,'Buffalo' as City union all
select 1001 as zip, 'Test8' as store,'NY' as state,'Buffalo' as City
insert into @ExpectedOutput(Zipcode,Name,State,City)
select 1001 as zip, 'Test1,Test2,Test3,Test4' as store,'NY' as state,'New York' as City union all
select 1001 as zip, 'Test5,Test6,Test7,Test8' as store,'NY' as state,'Buffalo' as City
select * from @table
select * from @ExpectedOutput
basically i need to combine the name as comma separated based on City,state, zip. Any sample query please