Says there's an error near the 'for' i'm tired and I can't see the issue.......
Code:
Select
Date, StoreID, LaneID, DriveThruCarID, DriveOn, DriveOff, OrderNumber, OrderTotal,
[OrderBoardDetector], [ServiceWindowDetector], [GreetDetector], [PaymentWindowDetector]
FROM
(
SELECT
Date,
DTC.StoreID,
SE.LaneID,
ServiceEventSource,
ServiceEventType,
MaxEventTime =MAX(SE.TimeStamp),
MinEventTime =Min(SE.TimeStamp),
DTCSE.DriveThruCarID,
--(DateDiff(s,Convert(datetime,Min(SE.TimeStamp),108),Convert(datetime,Max(SE.TimeStamp),108))),
--datediff(s,MIN(SE.TimeStamp), MAX(SE.TimeStamp)),
DriveOn,
DriveOff,
DTO.OrderNumber,
DTO.OrderTotal,
Goal=(SELECT TOP 1 TimeGoalSeconds FROM HAT_CENTRAL.dbo.fnc_BI_FetchGoal(Min(SE.TimeStamp), ServiceEventSource, '61D426D2-324E-4419-88B3-8EE24421C0F5'))
From
QTime_ServiceEvent SE
INNER JOIN QTime_DriveThruCarServiceEvent DTCSE
ON
SE.StoreID = DTCSE.StoreID
AND
SE.ServiceEventID = DTCSE.ServiceEventID
Inner Join QTime_DriveThruCar DTC
ON
DTC.StoreID = DTCSE.StoreID
and
DTC.DriveThruCarID = DTCSE.DriveThruCarID
Inner Join Dates D
ON
DTC.DateID = D.DateID
inner join QTime_DriveThruCarOrder DTCO
ON
DTC.StoreID = DTCO.StoreID
and
DTC.DriveThruCarID = DTCO.DriveThruCarID
inner join QTime_DriveThruOrder DTO
ON
DTCO.StoreID = DTO.StoreID
and
DTCO.OrderID = DTO.OrderID
Group By
DTCSE.DriveThruCarID,
ServiceEventType,
ServiceEventSource,
DriveOn,
DriveOff,
SE.LaneID,
D.Date,
DTC.StoreID,
OrderNumber,
DTO.OrderTotal
) SUB
PIVOT
(
MaxEventTime
for ServiceEventSource in (OrderBoardDetector, ServiceWindowDetector, GreetDetector, PaymentWindowDetector)
) A