Home Forums SQL Server 2008 T-SQL (SS2K8) Writing to local variable from CTE RE: Writing to local variable from CTE
Lynn Pettis
SSC Guru
Points: 442467
More actions
May 12, 2013 at 4:48 pm
#1614476
No, it can't.
A CTE only exists for the duration of the query with which is defined. You can't assign a value in a CTE to a variable for the same reason you can't do this:
select
MyCol1,
@MyVariable = MyCol2
from
dbo.MyTable;