Hello, I have a database that I can only read, that for I have not used VIews or stored procs to get this.
I have a log table for costumers, and I must compute the elapsed time since the last time the costumer got a service, in SQL I got this working (I am computing the elapsed time in minutes and hours).
SELECT P.*, DATEDIFF([minute], CAST(C_Date + ' ' + C_Time AS datetime), GETDATE()) AS difMinutes, DATEDIFF([hour],
CAST(C_Date + ' ' + C_Time AS datetime), GETDATE()) AS difHours
FROM CustomerState P
WHERE (Id =
(SELECT TOP 1 P1.Id
FROM CustomerState AS P1
WHERE P1.Customer_Id = P.Customer_Id
ORDER BY P1.C_Date DESC, P1.C_Time, P1.Id DESC))
ORDER BY Customer_ID
I have made a typed list and tryed to group and get a MAX but I am stocked, I would like to know if there is a better approach for this.
Regards