DECLARE @timeSpan TABLE
(id int,
Intime DATETIME,
Outtime DATETIME)
DECLARE @distance TABLE
(x float, y float)
INSERT into @timeSpan
(Id,intime,outtime)
SELECT row_number () over (order by Att.intime) ' rowindex ', att.intime,att.outtime
From attendance att
INNER JOIN Vehicle as Veh
On Att.employeeid=veh.id
WHERE intime between ' 2014/11/17 0:00:00 ' and ' 2014/11/17 10:14:00 ' and veh.vehicledepartmentid=3 and veh.vehicletype=1 an D veh.id=-297 and att.occday=20141117
ORDER BY Att.intime
DECLARE @count int
DECLARE @currentCount int
DECLARE @intime datetime
DECLARE @outtime datetime
Select @count = count (*) from @timeSpan
Set @currentCount =0
While @count > @currentCount
Begin
Set @currentCount [Email protected]+1
Select @intime =intime, @outtime =outtime from @timeSpan where @currentCount =id
INSERT into @distance
(x, Y)
Select X, y from (the Select Wp.*,wv.x,wv.y from (
SELECT Worksiteid,employeeid from Worksitepass where employeeid= ' -297 ' and stime between @intime and @outtime
) as WP INNER JOIN worksite as WV
On Wp.worksiteid=wv.number
INNER JOIN Vehicle as EV on Wp.employeeid=ev.id
Left join Devicelocmap as DLM on Dlm.number=wv.number) as T1
End
SELECT * FROM @distance
SQL Looping table, one of the criteria for a field in a table as a query statement