sql >> Database >  >> RDS >> Sqlserver

MS SQL data vergelijken?

SELECT CASE WHEN CAST(date1 AS DATE) <= CAST(date2 AS DATE) ...

Moet doen wat je nodig hebt.

Testcase

WITH dates(date1, date2, date3, date4)
     AS (SELECT CAST('20101231 15:13:48.593' AS DATETIME),
                CAST('20101231 00:00:00.000' AS DATETIME),
                CAST('20101231 15:13:48.593' AS DATETIME),
                CAST('20101231 00:00:00.000' AS DATETIME))
SELECT CASE
         WHEN CAST(date1 AS DATE) <= CAST(date2 AS DATE) THEN 'Y'
         ELSE 'N'
       END AS COMPARISON_WITH_CAST,
       CASE
         WHEN date3 <= date4 THEN 'Y'
         ELSE 'N'
       END AS COMPARISON_WITHOUT_CAST
FROM   dates 

Retourneren

COMPARISON_WITH_CAST   |  COMPARISON_WITHOUT_CAST
Y                         N


  1. MySQL-opgeslagen procedure veroorzaakte `Opdrachten niet gesynchroniseerd`

  2. JFreeChart met numerieke zoekopdracht ORACLE

  3. mysql query kamer beschikbaarheid

  4. verbind R met MySQL met RODBC met behulp van dsn