declare @temp nvarchar(100)
set @temp='end'+convert(char(10),getdate(),20)
print @temp
exec('select * into ' + @temp + ' from ttaxfee_send  where ttaxfee_send.MaketTime<=getDate()')

解决方案 »

  1.   

    这样做:
    declare @temp nvarchar(100),@sql varchar(500)
    set @temp='end'+convert(char(10),getdate(),20)
    print @temp
    set  @sql ='select * into '+@temp +'from ttaxfee_send  where ttaxfee_send.MaketTime<=getDate()'
    exec(@sql)
      

  2.   

    修改一下:
    declare @temp nvarchar(100),@sql varchar(500)
    set @temp='end'+convert(char(10),getdate(),20)
    print @temp
    set  @sql ='select * into '+@temp +' from ttaxfee_send  where ttaxfee_send.MaketTime<=getDate()'
    exec(@sql)
      

  3.   

    给你一个例子:
    declare @temp nvarchar(100),@sql varchar(500)
    set @temp='end'+convert(char(10),getdate(),20)
    print @temp
    set  @sql ='select * into ['+@temp +'] from northwind.dbo.products  where productid<=23'
    print(@sql)
    exec(@sql)
      

  4.   

    因为,在SQL中表名和字段是不可以通过变量来指定的
      

  5.   

    declare @temp nvarchar(100)
    set @temp='end'+convert(char(10),getdate(),20)
    print @temp
    exec ('select * into '+@temp+' from ttaxfee_send  where ttaxfee_send.MaketTime<=getDate()')