use 'between' with varchar (sql server)

后端 未结 3 1142
走了就别回头了
走了就别回头了 2021-01-20 10:33

Using SQL Server 2005 Express.

(
    CONVERT(VARCHAR(8), R.reviewStart, 108) between CONVERT(VARCHAR(8), M.meetingStart, 108) and CONVERT(VARCHAR(8), M.meeti         


        
3条回答
  •  清歌不尽
    2021-01-20 11:01

    Your first condition is equivalent to this more index friendly one:

    R.reviewStart >=  DATEADD(day, DATEDIFF(day, '19010101', M.meetingStart), '19010101') 
    and R.reviewStart < DATEADD(day, 1+DATEDIFF(day, '19010101', M.meetingStart), '19010101') 
    

    (explained here: Reuse Your Code with Table-Valued UDFs ) .

提交回复
热议问题