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

前端 未结 8 1684
悲哀的现实
悲哀的现实 2021-01-01 08:53

I have this code in my select statement

ISNULL(a.PolicySignedDateTime,aq.Amount) AS \'Signed Premium\',

But I want to see if \"a.PolicySign

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 09:09

    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

提交回复
热议问题