表名不能是变量,你可以用动态SQL语句来实现
use seattle
declare @i int
set @i=1
declare @accmile float
declare @mile float
declare @strsql nvarchar(4000)
declare m cursor
for (select Milepost from lianxiacc)
open m
fetch next from m into @accmile
while @@FETCH_STATUS = 0
begin
set @mile=(select max(milepost)from i5_2011_Jan where milepost<@accmile)
set @strsql='select * into sample'+cast(@i as varchar(20))+' from i5_2011_Jan where Milepost='+cast(@mile as varchar(50))
exec(@strsql)
set @i = @i+1
fetch next from m into @accmile
end