我正在尝试将datetime2
与time(7)
我需要帮助转换datatime2
。
这是我尝试过的:
DECLARE @PracticeStartTime time(7)
DECLARE @PracticeEndTime time(7)
SET @PracticeStartTime = (
SELECT PBH.StartTime
FROM PracticePractitioner AS PP WITH (NOLOCK)
LEFT JOIN PracticeBusinessHours AS PBH WITH (NOLOCK)
ON PBH.PracticeId = PP.PracticeId
WHERE PP.PractitionerId = @PractitionerId
)
SET @PracticeEndTime = (
SELECT PBH.EndTime
FROM PracticePractitioner AS PP WITH (NOLOCK)
LEFT JOIN PracticeBusinessHours AS PBH WITH (NOLOCK)
ON PBH.PracticeId = PP.PracticeId
WHERE PP.PractitionerId = @PractitionerId
)
IF (
(
CONVERT(@ScheduledStart AS TIME) BETWEEN @PracticeStartTime
AND @PracticeEndTime
)
AND (
CONVERT(@ScheduledEnd AS TIME) BETWEEN @PracticeStartTime
AND @PracticeEndTime
)
)
BEGIN
PRINT 'Time within practice hours';
END
ELSE
BEGIN
RETURN - 1
END
答案 0 :(得分:1)
您的语法已关闭。
我会使用CAST
cast(@ScheduledStart as time(7))
您可以使用CONVERT
convert(time(7), @ScheduledStart)