我在两次计算小时数时遇到问题,假设我的结束时间是晚上11:00,开始时间是晚上10:00,现在我想得到一个结果1 hours
。这里的结束时间必须小于或等于当前时间。 I am using sql server 2012 express edition.
任何想法都会对我有所帮助。
我的查询:
SELECT
VM_EventStageRoleShift.id,
VM_Event.EventName,
VM_EventStage.RaceDetail,
VM_EventStage.[Date],
VM_EventStageRoleShift.EventStageID,
VM_EventStageRoleShift.StartTime,
VM_EventStageRoleShift.EndTime,
VM_EventStageRoleShift.Location,
VM_EventStageRoleShift.BriefingTime,
VM_EventStageRoleShift.BriefingLocation,
SET_Role.PositionTitle,
DIFFERENCE(VM_EventStageRoleShift.EndTime,VM_EventStageRoleShift.StartTime) AS SystemLoggedHour --eg. 11:00PM - 10:00PM **(here is my problem)**
FROM
VM_Event
INNER JOIN VM_EventStage ON VM_EventStage.EventID = VM_Event.id
INNER JOIN VM_EventStageRole ON VM_EventStageRole.EventStageID = VM_EventStage.id
INNER JOIN VM_EventStageRoleDesc ON VM_EventStageRoleDesc.EventStageRoleID = VM_EventStageRole.id
INNER JOIN VM_EventStageRoleShift ON VM_EventStageRoleShift.EventStageRoleID = VM_EventStageRole.id
INNER JOIN SET_Role ON SET_Role.id = VM_EventStageRole.RoleID
WHERE
--VM_EventStageRoleDesc.ManagerID = @ManagerID
VM_EventStageRoleShift.[Status] <> 3
AND VM_EventStage.[Date] <= Convert(date, GETDATE())
AND VM_EventStageRoleShift.EndTime <= --CurrentTime **(here is my problem)**
N.B:EndTime和StartTime都是nvarchar(8)