Last night I was writing a simple T-SQL program something like this
DECLARE @ROLEID AS INT
SELECT @ROLEID = [ROLE ID] FROM TBLROLE
;WITH CTE
AS
(
SELE
Common table expressions are defined within the context of a single statement:
WITH cte_name AS (
)
;
So you can do something like:
WITH CTE
AS
(
SELECT * FROM SOMETABLE
)
SELECT * FROM CTE;
or
WITH CTE
AS
(
SELECT * FROM SOMETABLE
)
UPDATE CTE
SET somefield = somevalue
WHERE id = somekey;
A CTE must be followed by a single SELECT, INSERT, UPDATE, MERGE, or DELETE statement that references some or all the CTE columns. A CTE can also be specified in a CREATE VIEW statement as part of the defining SELECT statement of the view