views:

117

answers:

2

i want to add select query result into dataset, so i can write new query to run on it to get net dataset but how?

Original query:


MyDATASET=(
select x, y,z from table1
union all
select k,l,m from table2
)
i wan to this select * from this.MyDATASET
+1  A: 

Well, you could perhaps create a CTE, UDF or view? But it really isn't clear what you are trying to do...

CREATE VIEW MyView AS
    select x, y,z from table1
    union all
    select k,l,m from table2
GO

SELECT * FROM MyView
SELECT * FROM MyView WHERE x = 0

etc

Marc Gravell
I think a VIEW is probably what the OP is after.
Lieven
i add new version
Phsika
Thanks alot you are correct and my be genious!!!
Phsika
A: 

Assuming you want to cache data for re-use later...

Use a temp table or table variable if it's contained within one bit of code.

If you want to refer the same data in several processes or calls, then use a temp table. Use a local one for many calls but don't close the connecion, use a global one for many different processes/connections.

If it's just one big select where you want to re-use the same data, then use a CTE.

A view also works but the data may change between executions.

gbn