【问题标题】:SQL Server : convert Datetime2 into time(7)SQL Server : 将 Datetime2 转换为时间(7)
【发布时间】:2014-09-12 01:25:44
【问题描述】:

我正在尝试将datetime2time(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

【问题讨论】:

  • 您是否收到错误消息?这是 MSSQL 吗?
  • @JChao sql 错误:消息 102,级别 15,状态 1,过程 AppointmentByModalCreate,第 57 行“@ScheduledStart”附近的语法不正确。

标签: sql sql-server datetime time converter


【解决方案1】:

您的语法已关闭。

我会使用CAST

cast(@ScheduledStart as time(7))

你可以使用CONVERT

convert(time(7), @ScheduledStart)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    相关资源
    最近更新 更多