简体   繁体   English

将MSSQL Server 2008临时表导出到Excel电子表格

[英]Export MSSQL Server 2008 temp table into excel spreadsheet

I have a stored procedure created in MSSQL 2005 which stores the data in a global temp table (##Temp). 我在MSSQL 2005中创建了一个存储过程,该过程将数据存储在全局临时表(## Temp)中。 When i use the export wizard function in MSSQL 2005 I am able to export the data into a excel file. 当我在MSSQL 2005中使用导出向导功能时,可以将数据导出到excel文件中。

However when I run the same stored procedure in MSSQL 2008 and try to export the data in the temp table into a excel file using the export wizard, I am getting a Invalid object Name '##Temp' error. 但是,当我在MSSQL 2008中运行相同的存储过程,并尝试使用导出向导将临时表中的数据导出到excel文件时,出现了无效的对象名称'## Temp'错误。

May I know why is this so and How can I rectify it. 我可以知道为什么会这样,如何纠正它。 Please advise on how to solve it. 请提供解决方法的建议。

This is the part of the Stored Procedure where i am creating a global temp table 这是我创建全局临时表的存储过程的一部分

 SET @SQLStrMain = RTRIM(@SQLStrMain_Prefix)
 SET @SQLStrMain = @SQLStrMain + ',' + RTRIM(@SQLStrMain_Txn)
 SET @SQLStrMain = @SQLStrMain + ',' +  RTRIM(@SQLStrMain_Amt)
 SET @SQLStrMain = @SQLStrMain + ' INTO ##Temp '
 SET @SQLStrMain = @SQLStrMain + ' FROM ( '
 SET @SQLStrMain = @SQLStrMain + RTRIM(@SQLStrSub) 
 SET @SQLStrMain = @SQLStrMain + RTRIM(@SQLStrMain_Postfix)
 EXEC (SQLStrMain )

According to MSDN, MSSQL 2008 does supports ##Temp naming conventions 根据MSDN,MSSQL 2008确实支持## Temp命名约定

Using Radu Gheorghiu idea, I changed the ##Temp to TempTable(without the ##) and than i use the command 使用Radu Gheorghiu的想法,我将## Temp更改为TempTable(不使用##),然后使用命令

 Drop Table TempTable 

To remove the TempTable after executing the SP. 在执行SP之后删除TempTable。 So thus, whenever I rerun the sp i will not have any issues. 因此,每当我重新运行sp时,我都不会遇到任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM