日期:2014-05-18 浏览次数:20514 次
DECLARE @length int DECLARE @name int SET @length = 2 set @name=08 while @name<=31 BEGIN declare @strSql varchar(500) declare @_str varchar(10) set @_str=REPLICATE('0',@length-DATALENGTH(CONVERT(VARCHAR,@name)))+CONVERT(VARCHAR,@name) set @strSql= 'insert into S201001'+@_str+'select * from DATA2010.dbo.S201001' +@_str set @name = @name+1 execute(@strSql) End
DECLARE @length int DECLARE @name int SET @length = 2 set @name=08 while @name<=31 BEGIN declare @strSql varchar(500) declare @_str varchar(10) set @_str=REPLICATE('0',@length-DATALENGTH(CONVERT(VARCHAR,@name)))+CONVERT(VARCHAR,@name) set @strSql= 'insert into S201001'+@_str+' /*这里少空格*/select * from DATA2010.dbo.S201001' +@_str set @name = @name+1 execute(@strSql) End
------解决方案--------------------
select 和表格名字连在一起了,中间要添加一个空格。
------解决方案--------------------
print(@strSql)