Thursday, 15 July 2010

sql - CTE execute commands before using the CTE Table -



sql - CTE execute commands before using the CTE Table -

is there way write kind of code before selecting cte table ?

declare @testtable table (id int ,name nvarchar) insert @testtable values (1,'a'),(2,'b'),(1,'c') ;with tempcte(name) ( select name @testtable id = 1 ) print 'test' select * tempcte

no, cannot done. if refer msdn :

a mutual table look (cte) can thought of temporary result set defined within execution scope of single select, insert, update, delete, or create view statement.

so it's scope of single select/ insert/ update/ delete/ or create view statement holds cte result set. written after scope won't able access temporary data.you can read more here: http://msdn.microsoft.com/en-us/library/ms175972.aspx

sql sql-server tsql

No comments:

Post a Comment