You have to use CASE
SELECT CASE WHEN Field IS NOT NULL
THEN 'something'
ELSE 'something else'
END
Answer from Szymon on Stack OverflowNeed some knowledge on NULL and NOT NULL
Case When not check NULL value as defined
query - Not equal to operator is not returning NULL values in SQL Server - Database Administrators Stack Exchange
When NULL IS NOT NULL โ SQLServerCentral Forums
Videos
You have to use CASE
SELECT CASE WHEN Field IS NOT NULL
THEN 'something'
ELSE 'something else'
END
I know is late but just in case someone else viewing this and using MSSQL 2012 or above you could use 'IIF' statement.
I guess OP don't want to use 'IF' clausule cause is "too much code syntax" to acomplish simple stuff.
An alternative also cleaner than 'IF' statement is 'IIF'. Is just an inline 'IF' simplification.
SELECT IIF(X IS NULL, 'Is null', 'Not null') 'Column Name'
Regarding OP
SELECT IIF(a.PolicySignedDateTime IS NULL, NULL, aq.Amount) AS 'Signed Premium'
https://learn.microsoft.com/en-us/sql/t-sql/functions/logical-functions-iif-transact-sql?view=sql-server-ver15
-
Where and why exactly a null is used?
-
What is exactly null and not null? To my understanding Not null we use when its mandatory to insert some value in that field, also when we give check constraint so by default the column will be not null right?
-
By adding new column through alter method default values are null, so how would I be able to insert values in it and is it right to give not null constraint to that new column while adding through alter method, basically when null and when not null to be used?...
god this is so confusing please help me, ik im asking alot but im really confused
Consider checking documentation:
NULL indicates that the value is unknown. A null value is different from an empty or zero value. No two null values are equal. Comparisons between two null values, or between a null value and any other value, return unknown because the value of each NULL is unknown.
If you consider that the value of istrue is unknown in the NULL case then it might or might not equal 1.
The expression istrue != 1 then evaluates to unknown
SQL only returns rows where the WHERE clause evaluates to true.
If you are on SQL Server 2022+ you can use
WHERE istrue IS DISTINCT FROM 1
To give the inequality semantics that you want (Fiddle).