从选择查询动态创建和加载表 [英] dynamically create and load table from select query
本文介绍了从选择查询动态创建和加载表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT
MEM_ID, [C1],[C2]
from
(select
MEM_ID, Condition_id, condition_result
from tbl_GConditionResult
) x
pivot
(
sum(condition_result)
for condition_id in ([C1],[C2])
) p
以上查询返回三列数据.直到运行时我才知道 select 语句中有多少列.是否可以将 select 语句中的数据加载到动态创建的表中?处理完动态创建的表中的数据后,我想删除该表.
The above query returns three columns of data. Until runtime I will not know how many columns in the select statement. Is it possible to load the data from the select statement into a dynamically created table? After processing the data from the dynamically created table I want to drop the table.
感谢您的帮助.
史密斯
推荐答案
是的,做一个 SELECT INTO 例如
Yes, do a SELECT INTO e.g.
SELECT
MEM_ID, [C1],[C2]
into #TEMP
from
(select
MEM_ID, Condition_id, condition_result
from tbl_GConditionResult
) x
pivot
(
sum(condition_result)
for condition_id in ([C1],[C2])
) p
-- Do what you need with the TEMP table
DROP TABLE #TEMP
这篇关于从选择查询动态创建和加载表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文