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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -