在存储过程中写有如下语句
create table #templs(id0  nchar(100),id1  nchar(100),id2  nchar(100),id3  nchar(100),id4 int ,id5 int,id6  int,id7 int,id8  int)
select  @id_0 ,@id_1,@id_2,@id_3,@id_4,@id_5,@id_6,@id_7,@id_8  into  #templs
提示‘数据库中已存在#templs对象’,不知如何实现?

解决方案 »

  1.   

    单独写
    select @id_0 as id0,@id_1 as id1,@id_2 as id2,@id_3 as id3,@id_4 as id4,@id_5 as id5,@id_6 as id6,@id_7 as id7,@id_8 as id8 into #templs
    或者create table #templs(id0 nchar(100),id1  nchar(100),id2  nchar(100),id3  nchar(100),id4 int ,id5 int,id6  int,id7 int,id8  int)insert into #templs select @id_0,@id_1,@id_2,@id_3,@id_4,@id_5,@id_6,@id_7,@id_8
      

  2.   

    用insert into 
    select into 会自动创建表的insert   into  #templs 
    select  @id_0 ,@id_1,@id_2,@id_3,@id_4,@id_5,@id_6,@id_7,@id_8
    from 表
      

  3.   

    sorry 错了
    insert   into  #templs 
    select  @id_0 ,@id_1,@id_2,@id_3,@id_4,@id_5,@id_6,@id_7,@id_8
      

  4.   

    select into 是创建新表,所以不能这样写,你可以不用创建临时表,而直接用select去掉,也可以使用insert into 临时表 select * from 表
      

  5.   

    create table #templs(id0  nchar(100),id1  nchar(100),id2  nchar(100),id3  nchar(100),id4 int ,id5 int,id6  int,id7 int,id8  int)
    select  @id_0 ,@id_1,@id_2,@id_3,@id_4,@id_5,@id_6,@id_7,@id_8  into  #templs--用完临时表后一定要Drop
    drop table #templs