Download all codeblocks as file with an CTE

0

Please login or register to vote for this query.

(click on this box to dismiss)

https://meta.stackexchange.com/questions/364374

Physics

Q&A for active researchers, academics and students of physics

declare @userid int = ##userud?36296##

;with codeblocks(id,body,num,st,et) as
(
select id
     , body
     , 1 num
     , charindex(N'<pre><code>', body, 0) + 11 st
     , charindex(N'</code></pre>', body, 0) et
from posts
where owneruserid = @userid
and charindex(N'</code></pre>', body, 0) > 0
union all
select p.id
     , p.body
     , cb.num + 1 [num]
     , charindex(N'<pre><code>', p.body, cb.et + 11) + 11 st
     , charindex(N'</code></pre>', p.body, cb.et + 11) et
from posts p
inner join codeblocks cb on cb.id = p.id 
where owneruserid = @userid
and charindex(N'</code></pre>', p.body, cb.et + 11) > 0
)

select id, num, substring(body, st, et-st) code
from (
select *
from codeblocks
) data
order by id, num

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results