This view in SQL Server is getting records which we then display according to admin time, I need to do this in Oracle 10g now, what sort of differences do I have to convert for here?
/* Formatted on 1/29/2013 3:39:19 PM (QP5 v5.227.12220.39724) */
SELECT p.facility_key,
CAST (p.unit_code AS VARCHAR) + '-' + CAST (p.room AS VARCHAR)
AS unit_code,
p.first_name,
p.last_name,
m.admin_time,
CONVERT (varchar (5),
datediff (s,
m.admin_time,
getdate ())
/ 3600)
+ ':'
+ CONVERT (varchar (5),
datediff (s,
m.admin_time,
getdate ())% 3600 / 60)
AS ELAPSED
FROM OTEN.TEN_M_PATIENT_MAST AS P INNER JOIN
OP.ORD_M_ADMIN AS M ON P.PAT_NUMBER = M.PAT_NUMBER
WHERE (M.ADMIN_TIME BETWEEN DATEADD(DAY, - 1, GETDATE()) AND GETDATE())
If your elapsed time is less than 24 hours, then the following should work:
Some notes. First, I added a length to
varchar. You should do this in any database. Second, I simplified the datetime arithmetic to just use subtraction. I changedgetdate()tosysdate. And the “+”s with “||”s. Finally, to get the elapsed time in hh:mm:ss format, I used a trick. I take the difference, add to the current date, and just convert the fractional part to hh:mm:ss.