欧博百家乐CONVERT DATETIME to TIME and remove seconds a
My use case is I have daily jobs that are scheduled to run at a specific time. I want to alert when a job did not run. I thought TIME would be the most appropriate data type for the JobStartTime field since the field determines the expected daily start time for the job and there really is not a date associated with the expected start time.
DECLARE @Jobs TABLE
(
JobName VARCHAR(10),
JobStartTime TIME
)
INSERT INTO @Jobs (JobName,JobStartTime) VALUES ('Job1','07:05:00.0000')
INSERT INTO @Jobs (JobName,JobStartTime) VALUES ('Job2','08:05:00.0000')
SELECT * FROM @Jobs
DECLARE @Logs TABLE
(
JobName VARCHAR(10),
JobStartDateTime DATETIME
)
INSERT INTO @Logs (JobName,JobStartDateTime) VALUES ('Job1','2016-10-10 07:05:00.000')
SELECT
J.JobName,
JobStartDateTime,
CASE WHEN L.JobStartDateTime IS NOT NULL THEN 'Success' ELSE 'Failure' END
AS JobDailyRunStatus
FROM @Jobs J
LEFT JOIN @Logs L
ON J.JobName = L.JobName AND JobStartTime = TIMEFROMPARTS(datepart(hh,JobStartDateTime),datepart(n,JobStartDateTime),0,0,0)