I have this code in my select statement
ISNULL(a.PolicySignedDateTime,aq.Amount) AS 'Signed Premium',
But I want to see if "a.PolicySignedDateTime" is not null. Is there a easy function to do this which does not involve using a "if" statement?
Cheers guys
ISNULL uses the data type of the first parameter, COALESCE follows the CASE expression rules and returns the data type of value with the highest precedence. The NULLability of the result expression is different for ISNULL and COALESCE.
IFNULL is equivalent to ISNULL. IFNULL is equivalent to COALESCE except that IFNULL is called with only two arguments. ISNULL(a,b) is different from x IS NULL . The arguments can have any data type supported by Vertica.
ISNULL Function in SQL Server The ISNULL Function is a built-in function to replace nulls with specified replacement values. To use this function, all you need to do is pass the column name in the first parameter and in the second parameter pass the value with which you want to replace the null value.
Example 4: Difference between SQL Server ISNULL with IS NULL You might confuse between SQL Server ISNULL and IS NULL. We use IS NULL to identify NULL values in a table. For example, if we want to identify records in the employee table with NULL values in the Salary column, we can use IS NULL in where clause.
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://docs.microsoft.com/en-us/sql/t-sql/functions/logical-functions-iif-transact-sql?view=sql-server-ver15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With