Compare DATETIME and DATE ignoring time portion

前端 未结 5 2426
清酒与你
清酒与你 2020-11-27 03:13

I have two tables where column [date] is type of DATETIME2(0).

I have to compare two records only by theirs Date parts (day+month+year), di

5条回答
  •  一整个雨季
    2020-11-27 03:32

    Use the CAST to the new DATE data type in SQL Server 2008 to compare just the date portion:

    IF CAST(DateField1 AS DATE) = CAST(DateField2 AS DATE)
    

提交回复
热议问题