SQL比较日期

时间:2019-02-08 14:23:38

标签: sql sql-server

在SQL Server中,需要检查select的结果是否在where子句中。

尝试以下操作。但失败了。需要同样的帮助。

(SELECT FLDMODDATE 
 FROM EMPLOYEE 
 WHERE FLDRECNUMBER = 432893)  = '2019-02-05'

2 个答案:

答案 0 :(得分:1)

我认为您想要exists

select (case when exists (SELECT 1 
                          FROM EMPLOYEE 
                          WHERE FLDRECNUMBER = 432893 and FLDMODDATE  = '2019-02-05'
                         )
             then 'true' else 'false'
        end)

或者,如果使用的是T-SQL代码:

 if exists (SELECT 1 
            FROM EMPLOYEE 
            WHERE FLDRECNUMBER = 432893 and FLDMODDATE  = '2019-02-05'
           )

答案 1 :(得分:0)

您需要某种IF

IF (select FLDMODDATE from EMPLOYEE where FLDRECNUMBER = 432893)  = '2019-02-05'
BEGIN
    <Code here to do something>
END