Link to home
Start Free TrialLog in
Avatar of philsivyer
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

Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image


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
ASKER CERTIFIED SOLUTION
Avatar of RiteshShah
RiteshShah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of philsivyer
philsivyer

ASKER

RiteshShah

Yep - that works

Thanks
Thanks