相关文章推荐
博学的枇杷  ·  SQL中的嵌套CASE语句 - ·  2 月前    · 
唠叨的硬盘  ·  如何实现MySQL case when ...·  2 月前    · 
微笑的青蛙  ·  selenium ...·  1 月前    · 
帅呆的篮球  ·  子查詢 (SQL Server) - ...·  1 月前    · 
豪爽的热水瓶  ·  How to export a Hive ...·  3 周前    · 
安静的硬币  ·  Vue ...·  2 年前    · 
兴奋的板栗  ·  scala、spark,cannot ...·  2 年前    · 
How do I do a SELECT * INTO [temp table] FROM [EXEC SQL1+SQL2+SQL3] ? Not FROM [Table] and without defining [temp table] ?
Following is my syntax: EXEC @SQL1+@SQL2+@SQL3
i want to insert this resultset into temp table.
Please help me.
Thanks in advance.
What I have tried:
i have tried following two methods but it didn't work.
insert into #temptable exec(@SQL1+@SQL2+@SQL3) select * from #temptable
SELECT #temptable OPENROWSET( ' SQLNCLI' , ' Server=(local)\SQL2008;Trusted_Connection=yes;' , ' EXEC ' + @SQL1 + ' +' + @SQL2 + ' ,' + create table t1(code nvarchar ( 10 ), name nvarchar ( 64 )); insert into t1 values ( ' 001' , ' Jon Doe' ); insert into t1 values ( ' 002' , ' Michael Doe' ); -- prepare stored procedure create procedure getdata begin -- functional stuff select * from t1; actual code to execute sp and store in temp table
CREATE TABLE #temp code nvarchar ( 10 ), name nvarchar ( 64 ) INSERT INTO #temp Exec getdata SELECT * INTO #tempTable FROM OPENQUERY (YOURSERVERNAME, ' EXEC exec(@SQL1+@SQL2+@SQL3)' )
it requires additional permission on sqlserver and format the query string.
hint- [ ^ ]
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •