贴上代码,各位大哥帮我看看是哪里出错了
use data
  update [data].[dbo]. Table_sub_tmp2tmp3  set distance=null
declare @V1 float
declare @V2 float
declare @L float
declare @w2 datetime
declare @m int
declare @n int
declare @k float
set @n=1
select @m=MAX(loopnum)  from [data].[dbo].[Table_tmp2tmp3] 
 while(@n<@m)
  begin
 select @V1=SPEED  from [data].[dbo].[Table_tmp2tmp3]
 where [data].[dbo]. Table_tmp2tmp3.loopnum=@n
 select @V2=SPEED  from [data].[dbo].[Table_tmp2tmp3]
 where [data].[dbo]. Table_tmp2tmp3.loopnum=@n+1
  select @L=distance0 from [data].[dbo].[Table_tmp2tmp3]
 where [data].[dbo]. Table_tmp2tmp3.loopnum=@n  select @w2=tmp2start  from [data].[dbo].[Table_tmp2tmp3]
 where [data].[dbo]. Table_tmp2tmp3.loopnum=@n+1
 declare @RTime datetime
 declare my_cursor cursor scroll dynamic forselect  [RTime]   from [data].[dbo].[table_sub_tmp2tmp3]
where [data].[dbo].[table_sub_tmp2tmp3].loopnum=@n order by rtime
 open my_cursor            
 
 ------进不去while
 while(@@FETCH_STATUS=0)
begin

fetch next from my_cursor into 
       @RTime
      
update [data].[dbo].[table_sub_tmp2tmp3] set distance=@L+(@V1-@V2)*DATEDIFF(S,@w2,@RTime)
  where [data].[dbo]. Table_sub_tmp2tmp3.RTime=@RTime
select @k=distance  from [data].[dbo].[Table_sub_tmp2tmp3]
 where [data].[dbo]. Table_sub_tmp2tmp3.RTime=@RTime

 
 end
  close my_cursor
deallocate my_cursor
  set @n=@n+1
 end
 select *from [data].[dbo].[table_sub_tmp2tmp3] ORDER BY RTIME

解决方案 »

  1.   

    ------进不去while
    ----让游标游起来
    fetch next from my_cursor into  
      @RTime while(@@FETCH_STATUS=0)
    beginfetch next from my_cursor into  
      @RTime
        
    update [data].[dbo].[table_sub_tmp2tmp3] set distance=@L+(@V1-@V2)*DATEDIFF(S,@w2,@RTime)
      where [data].[dbo]. Table_sub_tmp2tmp3.RTime=@RTime
    select @k=distance from [data].[dbo].[Table_sub_tmp2tmp3]
     where [data].[dbo]. Table_sub_tmp2tmp3.RTime=@RTime  
     end