I need to run 3 consecutive queries using the same derived table… I’m using MS SQL Server 2008
Select a,b,c from categories inner join (select x,y,z from derivedTable where…) …
Select a,b,c from users inner join (select x,y,z from derivedTable where…) …
Select a,b,c from orders inner join (select x,y,z from derivedTable where…) …
Is there a way to run the 3 sql queries at the same time in a way the derived table
(select x,y,z from derivedTable where ...)
is executed only once?
I’m using .net so… I’m wondering if I could return the 3 tables and load a dataset with the 3 tables.
Thanks
You could use
WITH:Note: As pointed by @Martin
WITHis evaluated several times so the correct solution is the temporary table.or a temporary table: