aggregation of comma-separated values in-position

Viewed 255

I have one table where there is two column loan no and counter_value.

Against each loan no there is the list of comma separated values are stored.

declare @tbl table (loanno varchar(100) , counter_value varchar(200) )

insert into @tbl
values(‘pr0021’,‘1000,200,300,100,800,230’),
(‘pr0021’,‘500,300,300,100,600,200’),
(‘pr0021’,‘500,100,200,190,400,100’)

I need to do grouping according to loan no and in-position aggregation (summation) on counter values. I need the output like below.

loanno  counter_value
pr0021  2000,600,800,390,1800,530
2 Answers
Related