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

前端 未结 8 1680
悲哀的现实
悲哀的现实 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:23

    It seems to me this would be an easy way to get the opposite.

    SELECT (1-ISNULL(field));

    Will give you 1 if NOT NULL and 0 if NULL instead of the 1 for NULL and 0 for NOT NULL

    0 讨论(0)
  • 2021-01-01 09:27

    There is no opposite function but you can do it without CASE.

    Use the fact that a string + 'something' will be NULL if string is NULL, and if that is null then use ISNULL to return 'somethingelse', get end of the returned value with RIGHT() and check that against 'something' using NULLIF, and then use COALESCE to do what you'd like to do if that is NULL (meaning original value is not null).

    Example:

    declare @text varchar(20) = 'some text or value'
    
    select COALESCE(NULLIF(RIGHT(ISNULL(@text + 'NOT', 'IS ') + 'NULL', 7), 'NOTNULL'), 'NOT NULL')
    

    Try this code and also try it with no value for @text.

    0 讨论(0)
提交回复
热议问题