/****** Script for SelectTopNRows command from SSMS ******/
declare @i int
set @i=400001
while @i < 400003
begin
declare @tbname varchar(12)
declare @sql varchar(255)
set @tbname = 'Min50' + STR(@i)
set @sql = 'select * from ' + @tbname + ' where Volumn != 0'
exec(@sql)
set @i = @i + 1
end
一直报错误:
Msg 170, Level 15, State 1, Line 1
第 1 行: '400' 附近有语法错误。
Msg 170, Level 15, State 1, Line 1
第 1 行: '400' 附近有语法错误。
求高人指点。。。
------解决方案--------------------
这样试试
- SQL code
declare @i intset @i=400001while @i < 400003begindeclare @tbname varchar(50)declare @sql varchar(255)set @tbname = 'Min50' + RTRIM(@i)set @sql = 'select * from ' + @tbname + ' where Volumn != 0'exec(@sql)set @i = @i + 1end
------解决方案--------------------
- SQL code
/****** Script for SelectTopNRows command from SSMS ******/declare @i intset @i=400001while @i < 400003begindeclare @tbname varchar(12)declare @sql varchar(255)set @tbname = 'Min50' + convert(varchar(6),@i)set @sql = 'select * from ' + @tbname + ' where Volumn != 0'exec(@sql)set @i = @i + 1end