Solution to TSQL Beginners Challenge 23
;with cte as
(
select data orig_data,data,LEN(datatoreplace) posn,DataToReplace,ReplacedWithData
from @t
union all
select t.Data orig_data,convert( varchar(20),REPLACE(cte.data,substring(cte.datatoreplace,cte.posn,1),substring(cte.replacedwithdata,cte.posn,1))) data,
posn = posn-1,t.DataToReplace,t.ReplacedWithData
from cte,@t t
where posn>0
)
select orig_data as OriginalData,Data as TranslatedData
from cte
where posn=0
Tags: