Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a opposite function to ISNULL in sql server? To do Is not null?

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

like image 702
Bobby Avatar asked Oct 08 '13 08:10

Bobby


People also ask

IS NOT NULL vs coalesce?

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.

What is the difference between Isnull and Ifnull in SQL?

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.

How do I replace Isnull in SQL Server?

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.

Is NULL vs Isnull SQL Server?

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.


2 Answers

You have to use CASE

SELECT CASE WHEN Field IS NOT NULL     THEN 'something'     ELSE 'something else' END 
like image 146
Szymon Avatar answered Sep 21 '22 15:09

Szymon


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

like image 24
gsubiran Avatar answered Sep 23 '22 15:09

gsubiran