declare @tstr varchar(100)
, @i int
, @tsql varchar(5000)
, @k int
create table #tbTemp
(aa varchar(50))
set @k = 1
while exists (select aa from tempTb where idx = @k)
Begin
select @tstr=aa from tempTb where idx = @k
select @i = charindex('||', @tstr)
if @i > 0
begin
while @i > 0
begin
insert into #tbTemp values(left(@tstr, charIndex('||', @tstr)-1))
select @tstr = substring(@tstr, charindex('||', @tstr) + 2, len(@tstr))
select @i = charindex('||' , @tstr)
end
select @tsql = left(@tsql, len(@tsql)-2)
insert into #tbTemp values (@tstr)
end
else
insert into #tbTemp values(@tstr)
set @k = @k + 1
End
select aa, count(aa) as cnt from #tbTemp
group by aa
order by aa
drop table #tbTemp
Posted by 홍반장