我怎么把一个exce('')生成的表插入到一个临时表中,如下面的格式的格式怎么写?比如这里得到一个表:exec('select * from student where 姓名='''+@name+''''),我怎么把这个表的数据插入到一个临时表里?
insert #tab select exec('select * from student where 姓名='''+@name+'''')这个怎么修改才行?

解决方案 »

  1.   

    exec('insert #tab  select * from student where 姓名='''+@name+'''')
      

  2.   

    exec('select * into table-name from student where 姓名='''+@name+''''),
      

  3.   

    --如果表#tab 存在.exec('insert #tab select * from student where 姓名='''+@name+'''' + '; select * from #tab')
    )--如果表#tab不存在.
    exec('select * into #tab from student where 姓名='''+@name+'''' + '; select * from #tab')
      

  4.   

    declare @t table(i int)
    insert @t exec('select 1 a union all select 2')
    select * from @t
    /*
    i
    -----------
    1
    2(2 行受影响)
    */直接插不就完了吗
      

  5.   

    insert #tab exec('select * from student where 姓名='''+@name+'''')
    2005以上可以这样
      

  6.   


    insert #tab select exec('select * from student where 姓名='''+@name+''''……去掉 select 就行了
      

  7.   

    应当可以  
    insert into #tab select exec('select 1 union all select 2')