[英]SQL Server : convert Datetime2 into time(7)
I am trying to compare a datetime2
with a time(7)
我正在尝试将datetime2
与time(7)
进行比较time(7)
I need help converting the datatime2
. 我需要转换datatime2
帮助。
This is what I've tried: 这是我尝试过的:
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
Your syntax is off. 您的语法已关闭。
I would use CAST
我会使用CAST
cast(@ScheduledStart as time(7))
You could use CONVERT
您可以使用CONVERT
convert(time(7), @ScheduledStart)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.