philsivyer
asked on
Using Temp Table and With Clause and Union - MS SQL SERVER
Is it possible to create a Temp Table when using a With clause and Union
eg
Create Table #T1
(
)
Insert into T1
With test as (
Select ....
From
)
Select
..
From test
UNION
Select
...
From
Table
eg
Create Table #T1
(
)
Insert into T1
With test as (
Select ....
From
)
Select
..
From test
UNION
Select
...
From
Table
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
RiteshShah
Yep - that works
Thanks
Yep - that works
Thanks
ASKER
Thanks
If I am right...
You can use the CTE only after it's declared.
ie.,
With test as
(
Select ...
)
Only in one sql query you can refer CTE table after declaration.
So answer to question is it is not possible to do like that
So this will only work
Create Table #T1
(
)
With test as
(
Select ....
From
)
Insert into T1
Select
..
From test
UNION
Select
...
From
Table
Raj