其中convert(varchar(10)表示日期之间不起作用

时间:2016-11-11 14:57:35

标签: sql sql-server

我正在尝试将BETWEEN用于日期,但它仍然失败,因为它只返回所有结果,如果我做=或者它工作正常但是没有人可以帮助,谢谢

WHERE CASE 
    WHEN [BVContact] IS NOT NULL
        THEN convert(VARCHAR(10), [ContactStarted], 103)
    WHEN [TelephoneConsultationStartedBy] IS NOT NULL
        THEN convert(VARCHAR(10), [TelephoneConsultationStarted], 103)
    WHEN [HomeVisitContactBy] IS NOT NULL
        THEN convert(VARCHAR(10), [HomeVisitContactStarted], 103)
    ELSE ''
    END between '01/10/2016'
    AND '02/10/2016'

1 个答案:

答案 0 :(得分:-1)

    WHERE CASE 
    WHEN [BVContact] IS NOT NULL
        THEN convert(VARCHAR(10), [ContactStarted], 120)
    WHEN [TelephoneConsultationStartedBy] IS NOT NULL
        THEN convert(VARCHAR(10), [TelephoneConsultationStarted], 120)
    WHEN [HomeVisitContactBy] IS NOT NULL
        THEN convert(VARCHAR(10), [HomeVisitContactStarted], 120)
    ELSE ''
    END between '2016-10-01'
    AND '2016-10-02'