Skip to content

Instantly share code, notes, and snippets.

@erikdarlingdata
Last active July 31, 2021 18:04
Show Gist options
  • Save erikdarlingdata/b9744f72f86e4f7bd7c2c0d47821cfdf to your computer and use it in GitHub Desktop.
Save erikdarlingdata/b9744f72f86e4f7bd7c2c0d47821cfdf to your computer and use it in GitHub Desktop.
SELECT
n = 1,
query =
N'SELECT records = COUNT_BIG(*)
FROM dbo.Posts AS p1'
UNION ALL
SELECT
n = 2147483648,
N'OPTION(MERGE JOIN, FORCE ORDER, MAXDOP 2);'
UNION ALL
SELECT
n = x.n,
N'JOIN dbo.Posts AS p' +
RTRIM(x.n) +
N' ON p' +
RTRIM(x.n - 1) +
N'.ParentId = p' +
RTRIM(x.n) +
N'.ParentId'
FROM
(
SELECT
ROW_NUMBER() OVER
(
ORDER BY
1/0
) AS n
FROM sys.messages AS m
)AS x
WHERE x.n > 1
AND x.n <= 317
ORDER BY n;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment