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
2 个解决方案
#1
Well, you could perhaps create a CTE, UDF or view? But it really isn't clear what you are trying to do...
那么,你可以创建一个CTE,UDF或视图?但是你真的不清楚你要做什么......
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
#2
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.
如果只是一个大的选择,你想重新使用相同的数据,那么使用CTE。
A view also works but the data may change between executions.
视图也有效,但数据可能会在执行之间发生变化。
#1
Well, you could perhaps create a CTE, UDF or view? But it really isn't clear what you are trying to do...
那么,你可以创建一个CTE,UDF或视图?但是你真的不清楚你要做什么......
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
#2
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.
如果只是一个大的选择,你想重新使用相同的数据,那么使用CTE。
A view also works but the data may change between executions.
视图也有效,但数据可能会在执行之间发生变化。