比如这里得到一个表:exec('select * from student where 姓名='''+@name+''''),我怎么把这个表的数据插入到一个临时表里? insert #tab select exec('select * from student where 姓名='''+@name+'''')这个怎么修改才行?exec('insert #tab select * from student where 姓名='''+@name+'''') SQL code: exec('select * into table-name from student where 姓名='''+@name+''''),
--如果表#tab 存在.
exec('insert #tab select * from student where 姓名='''+@name+'''' + '; select * from #tab') )
--如果表#tab不存在. exec('select * into #tab from student where 姓名='''+@name+'''' + '; select * from #tab')
SQL code: declare @t table(i int) insert @t exec('select 1 a union all select 2') select * from @t /* i ----------- 1 2
(2 行受影响) */ 直接插不就完了吗 SQL code: insert #tab exec('select * from student where 姓名='''+@name+'''')