Question : Using a CTE with multiple queries

I've created a stored procedure that uses a CTE.   I would like for the stored procedure to return two different result sets, both based off of the CTE.  Each query in the sp runs fine by itself but when I try and run them together the second query throws an Invalid Object error.  Can you only use a CTE once?  Is there a way to make sure it's available to the next query without creating it again?

Answer : Using a CTE with multiple queries

if you want two resulsets you need two queries so it goes


;with CTE as (
select ....
)
select * from CTE

;with CTE1 as (
select ....
)
select * from CTE1

you cannot "reuse" the first one  

Random Solutions  
 
programming4us programming4us