Skip to content

Instantly share code, notes, and snippets.

@AndreasLazar
Created January 27, 2012 09:15
Show Gist options
  • Save AndreasLazar/1687905 to your computer and use it in GitHub Desktop.
Save AndreasLazar/1687905 to your computer and use it in GitHub Desktop.
Using cursor with Common Table Expressions
-- declare a cursor above the CTE definitions
DECLARE myCursor CURSOR FAST_FORWARD_FOR
-- declare CTEs
WITH CTE1 AS
(
-- CTE1 definitiion
)
,CTE2 AS
(
-- CTE2 definitiion
)
-- select query as normal
SELECT ... FROM CTE2
-- now open and use the cursor and don't forget to close
-- and deallocate it in the end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment