SQL批量导入数据,哪里错了?帮忙看下
DECLARE @length intDECLARE @name intSET @length = 2set @name=08while @name<=31BEGIN 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 intDECLARE @name intSET @length = 2set @name=08while @name<=31BEGIN 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)