日期:2014-05-18 浏览次数:20543 次
while(@number<=@result) begin set @sql='SET @sum=(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime<='''+CONVERT(VARCHAR(19),@e,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime desc )))-(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime>='''+CONVERT(VARCHAR(19),@s,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime asc)))' set @number=@number+1 if(@sum<>0 or @sum is not null) begin set @Mileage=@Mileage+@sum end set @s=DATEADD(d,1,@s) set @e=DATEADD(d,1,@e) set @GpsPath='dbo.GpsPath'+CONVERT( VARCHAR(8), CAST(FLOOR(CAST(@s AS FLOAT)) AS DATETIME), 112) end
=(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime<='''+CONVERT(VARCHAR(19),@e,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime desc )))-(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime>='''+CONVERT(VARCHAR(19),@s,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime asc)))
declare @sum numeric(18,0) declare @sql nvarchar(4000) set @sql='SET @sum=(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime<='''+CONVERT(VARCHAR(19),@e,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime desc )))-(Convert(int,(SELECT top 1 Mileage FROM '+@GpsPath +' WHERE GpsTime>='''+CONVERT(VARCHAR(19),@s,120)+''' AND TerminalNo='''+'02200051'+''' ORDER BY GpsTime asc)))' exec sp_executesql @sql,N'@sum numeric(18,0) output',@sum output print @sum