Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Given the table is ---

depot_code              dealer_code               dealer_child_code
---------------------------------------------------------------------
032                        70554                      70554
032                        70554                      77182



But i want to show the output as --

depot_code              dealer_code               dealer_child_code
---------------------------------------------------------------------
032                        70554                    70554, 77182



using cursor, please help as early as possible...

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 14-Feb-14 8:10am
v2
Comments
Chandrakanta.Sen 15-Feb-14 2:36am    
thanks for help ...
but i want to solve this by cursor in stored procedure...
please help...

1 solution

One easy way i like to use is this:
SQL
create table #t (id int, name varchar(20))

insert into #t
values (1, 'Matt'), (1, 'Rocks'), (2, 'Stylus')

select  id
        ,Names = stuff((select ', ' + name as [text()]
        from #t xt
        where xt.id = t.id
        for xml path('')), 1, 2, '')
from #t t
group by id


i got the example from here:
http://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings[^]

Try searching for "tsql aggregate string concatenation", that should put you on the right path.
 
Share this answer
 
Comments
King Fisher 14-Feb-14 23:42pm    
good one..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900