declare @table table(a int,b varchar(40))
insert into @table select * from tab上面的这个怎么写成:
exec ('insert into '+@table+' select * from tab') 注: 这种是会提示错误。
 

解决方案 »

  1.   

    insert into @table exec ('select * from tab') 
      

  2.   


    动态SQL语句中不能使用表变量.如果要用则用临时表比较好
    如:create table #a(a int,b varchar(40))exec ('insert into #a select * from tab')
    drop table #a
      

  3.   

    给你两个链接参考下,有存储过程,有调用,不知道是不是你要的
    http://hi.baidu.com/84ww/blog/item/695f904be29cbcf282025cca.html
    http://hi.baidu.com/84ww/blog/item/9e8b64ee47e29af9b2fb95cb.html