我有SQL語句如下:的SQL Server:如何檢查是否返回字段的值不爲空
SELECT ReturnDate
FROM <joins>
WHERE <conditions>
如何檢查是否ReturnDate不爲空?
我有SQL語句如下:的SQL Server:如何檢查是否返回字段的值不爲空
SELECT ReturnDate
FROM <joins>
WHERE <conditions>
如何檢查是否ReturnDate不爲空?
您可以使用CASE
與IS NULL
(或IS NOT NULL
):
SELECT CASE
WHEN ReturnDate IS NULL THEN 'It is null'
ELSE 'It is not null'
END AS IsItNull
FROM dbo.tablename ....
如果需要篩選NULL/NOT NULL
值也可以使用IS NOT NULL
:
WHERE ReturnDate IS NOT NULL ...
如果你不想選擇它爲空的任何記錄,使用類似:
SELECT ReturnDate
FROM <joins>
WHERE ReturnDate IS NOT NULL AND <conditions>
檢查returnDate的 「IS NULL」
嘗試此查詢
SELECT ReturnDate
FROM joins
WHERE conditions AND ReturnDate IS NOT NULL;