DECLARE @QuestionId int = ##relatedpostid##; WITH R AS ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @QuestionId int = ##relatedpostid##;


WITH R AS
(
SELECT @QuestionId AS PostId, 0 AS Level, CAST(CONCAT('/',@QuestionId,'/') AS VARCHAR(8000)) AS Path
UNION ALL
SELECT pl.PostId, Level + 1, CONCAT(Path , pl.PostId, '/')
from PostLinks pl
JOIN R ON R.PostId = pl.RelatedPostId
where pl.LinkTypeId=3 AND Path NOT LIKE CONCAT('/',pl.PostId,'/')
)
SELECT PostId as [Post Link], Level, Path
FROM R
JOIN Posts p on p.Id=R.PostId
WHERE Level > 0

Enter Parameters

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