Skip to content

Instantly share code, notes, and snippets.

@sqlparser
Created April 8, 2014 07:20
Show Gist options
  • Save sqlparser/10099189 to your computer and use it in GitHub Desktop.
Save sqlparser/10099189 to your computer and use it in GitHub Desktop.
common table expression
WITH mycte(x) AS (SELECT x = Convert( VARCHAR(1000), 'hello' )
UNION ALL
SELECT Convert( VARCHAR(1000), x + 'a' )
FROM mycte
WHERE Len( x ) < 10
UNION ALL
SELECT Convert( VARCHAR(1000), x + 'b' )
FROM mycte
WHERE Len( x ) < 10)
SELECT x
FROM mycte
ORDER BY Len( x ),
x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment