本文介绍了如何将exec sp_executesql @query中的数据存储到临时表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我想将数据存储到临时表中,来自exec sp_executesql @query语句 但是我无法那样做。 我尝试了什么: set @ query1 = N ' SELECT EmployeeCode,' + @cols + N ' 来自(选择EmployeeCode,活动,实际来自#target1 )x pivot ( max(Actual) for(' + @ cols + N ' ))p' select * 进入 #temp 来自 exec sp_executesql @ query ; 我在最后一行错误的语法错误解决方案 尝试: 创建 TABLE #tempTable(Column1 INT ,Column2 UNIQUEIDENTIFIER ,Column3 DATE ) INSERT INTO #tempTable(Column1,Column2,Column3) EXEC sp_executesql @ query SELECT * FROM #tempTable DROP TABLE #tempTable 或者更好,用表值函数替换你的SP。 CREATE 表 #tempTable(id int ); sp_executesql ' INSERT INTO #tempTable SELECT myId FROM myTable'; SELECT * FROM #tempTable; Hi All,I want to store data into temporary table from exec sp_executesql @query statementbut i am not able to do that.What I have tried:set @query1 = N'SELECT EmployeeCode, ' + @cols + N' from ( select EmployeeCode, activity,Actual from #target1 ) x pivot ( max(Actual) for activity in (' + @cols + N') ) p 'select * into #temp from exec sp_executesql @query;I got Error in last line incorrect syntax 解决方案 Try:CREATE TABLE #tempTable(Column1 INT, Column2 UNIQUEIDENTIFIER, Column3 DATE)INSERT INTO #tempTable(Column1, Column2, Column3) EXEC sp_executesql @querySELECT * FROM #tempTableDROP TABLE #tempTableOr better, replace your SP with a table valued function.CREATE TABLE #tempTable(id int);sp_executesql 'INSERT INTO #tempTable SELECT myId FROM myTable';SELECT * FROM #tempTable; 这篇关于如何将exec sp_executesql @query中的数据存储到临时表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 08:43