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

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

提交回复
热议问题