[Solved] Need Query – Row count with loop


    declare @timediff table(id int identity(1,1),Name varchar(50),logtime datetime)
    insert into @timediff Select Name,logtime from timediff

   declare @datetimeDiff int
   declare @i int=1
   while(@i<=(Select count(*) from @timediff))
     Begin
         Select @datetimeDiff=datediff(hour,logtime,
         (Select logtime from  @timediff where id=@i+1)) 
         from @timediff  where id=@i
         if(@datetimeDiff>=1)
         BEGIN
         Select @datetimeDiff
         --You can write your update code here

        END


        Set @i=@i+2
      END

0

solved Need Query – Row count with loop