ALTER PROCEDURE [dbo].[dtdiff]
-- 传入的参数
AS
--存储过程内部需要的变量
declare @id int
declare @trianNo varchar
declare @passTime1 datetime
declare @passTime2 datetime
declare @time_s int -- 时间间隔S
declare @id1 int
declare @sql varchar
--定义一个游标
declare CS cursor for
select id,trainNo,passTime from Train
open CS
FETCH NEXT FROM CS INTO @id,@trianNo,@passTime1
while(@@FETCH_STATUS=0)
BEGIN
--计算逻辑求时间差
select @time_s=DATEDIFF(SS,@passTime1,passTime) from train where ID=@id1+1
--如何输出时间差?如:
print convert(nvarchar,@time_s)
FETCH NEXT FROM CS INTO @id,@trianNo,@passTime1
END
close CS
deallocate CS
return
试一下,如何输出部分,我不清楚你的需求