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

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -