sql - Concatenating strings based on previous row values -
consider following input:
id -------- 33 272 317 318
i need somehow following result:
result -------- /33 /33/272 /33/272/317 /33/272/317/318
how can achieve single select statement?
using cross apply
, for xml path()
:
;with cte as( select *, rn = row_number() over(order (select null)) tbl ) select * cte c cross apply( select '/' + convert(varchar(10), id) cte rn <= c.rn xml path('') )x(s)
Comments
Post a Comment