从动态查询表输出将数据插入临时表 [英] Insert data into temporary table from dynamic query table output

查看:168
本文介绍了从动态查询表输出将数据插入临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中运行以下动态查询,并使用链接服务器连接到OLAP服务器,该服务器将返回一个表。

I have the below dynamic query run in SQL Server, connecting to an OLAP server using a linked server, which returns a table as a result.

SET @nSQL = EXECUTE ('SELECT non empty {
[Coded Season].[Coded Season].[Coded Season] *
[Season].[Season].[Season] *
[Product].[Subclass].[Subclass] *
[Product].[Subclass Id].[Subclass Id]
} ON ROWS,{
[Measures].[Pl No of Range Opts]
} ON COLUMNS
FROM RP_C0') AT AS_T_RP_5900_Admin

我正在像这样在SQL Server中执行它:

I am executing it in SQL Server like this:

exec sp_executesql @nSQL;

它返回一个值表。现在,我想将数据插入临时表中。我已经尝试了下面的代码,但是没有用。

It returns a table of values. Now I want to insert the data into a temporary table. I have tried the below code, but its not working.

INSERT INTO ##Subclass_Season_AS 
exec sp_executesql @nSQL;

也尝试过,

set @strNewQuery ='SELECT '+@nSQL+' INTO ##temptablename '
exec @strNewQuery

您能帮忙吗?谢谢!

推荐答案

您可能希望尝试将INTO语句放入动态查询中。

You may want to try to put the INTO statement in your dynamic query.

SET @nSQL = EXECUTE ('SELECT non empty {
[Coded Season].[Coded Season].[Coded Season] *
[Season].[Season].[Season] *
[Product].[Subclass].[Subclass] *
[Product].[Subclass Id].[Subclass Id]
} ON ROWS,{
[Measures].[Pl No of Range Opts]
} ON COLUMNS
INTO ##temptablename
FROM RP_C0') AT AS_T_RP_5900_Admin

这篇关于从动态查询表输出将数据插入临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆