trevormcg
7/27/2016 - 9:32 PM

MattWork

MattWork

declare @combinedcategories varchar(100) = '1/4/3/3/4/10/'
;


with ctesequence (seqno) as

(
       select charindex('/', @combinedcategories) 
       union all
       select charindex('/', @combinedcategories, seqno +1) 
       from ctesequence
       where seqno < len(@combinedcategories)-1
)


select left(( replace( replace ((select cast ((select distinct (replace(substring(@combinedcategories, seqno-2, 3), '/', '')) + '/' as [ac] from ctesequence [c]
for xml path ('')) as varchar(max))), '<ac>', '') , '</ac>', '')), len(((select replace( replace ((select cast ((select distinct (replace(substring(@combinedcategories, seqno-2, 3), '/', '')) + '/' as [ac] from ctesequence [c]
for xml path ('')) as varchar(max))), '<ac>', '') , '</ac>', '')))) - 1)