我要写个存储过程,里面要用到临时表,但临时表的结构是变化的。是随着传入参数table name改变而改变的。我应该怎么做?谢谢大家。急

解决方案 »

  1.   

    用动态语句如:
    exec('create table '+@table+'(字段)')
      

  2.   

    临时表结构可以这样
    if object_id('tmp') is not null
        drop table tmp
    exec('select * into tmp from '+@table)
      

  3.   

    临时表结构可以这样
    if object_id('tmp') is not null
    drop table tmp
    exec('select * into tmp from '+@table+' where 1<>0')
      

  4.   

    呵呵,还是错了
    临时表结构可以这样
    if object_id('tmp') is not null
        drop table tmp
    exec('select * into tmp from '+@table+' where 1=0')