我写的sql语句,都是报那个年份附近有错,那个高手帮忙指点一下,declare @table varchar(20),@sql varchar(4000)
select @table=convert(varchar(10),year(getdate()))+'w01'
select @sql='select * into '+@table+ ' from w01 where year(w01_002)=year(getdate())'
select @sql
exec (@sql)
select @table=convert(varchar(10),year(getdate()))+'w01'
select @sql='select * into '+@table+ ' from w01 where year(w01_002)=year(getdate())'
select @sql
exec (@sql)
select @table=cast((year(getdate()) as char(4))+'w01'
select @sql='select * into '+@table+ ' from w01 where year(w01_002)=year(getdate())'
select @sql
exec (@sql)
begin
set @table=cast(@minyear as varchar)+'w01'
select @sql='select * into ['+@table+ '] from w01 where year(w01_002) = '+cast(@minyear as varchar)
print @sql
set @minyear=@minyear+1
end