Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: How to check if the value of returned field is not null

I have SQL statement as follows:

SELECT  ReturnDate
FROM    <joins>
WHERE   <conditions>

How to check if ReturnDate is not null?

like image 413
tesicg Avatar asked Nov 05 '25 22:11

tesicg


1 Answers

You can use CASE with IS NULL (or IS NOT NULL):

SELECT CASE 
         WHEN ReturnDate IS NULL THEN 'It is null' 
         ELSE 'It is not null' 
       END AS IsItNull 
FROM   dbo.tablename ....

If you need to filter for NULL/NOT NULL values you can also use IS NOT NULL:

WHERE ReturnDate IS NOT NULL  ...
like image 106
Tim Schmelter Avatar answered Nov 09 '25 00:11

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!