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
Since we are in DBMS environment, it is possible to use set-based approach. So, assuming that table has an identifier field (id) - primary key or unique and not null, the job can be done this way:
If value field is of character data type some char function should be used. So, practical implementation of the approach might be as below:
Another option to get NOT NULL sign in form of 1 is to use conversion of flag_field value to bit:
This works when conversion to bit is available for your flag_field data type and is usefull when you can consider 0-values and NULLs as same NO VALUE. Represented by NULL or 0 - as you choose:
You have to use
CASE
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:
Try this code and also try it with no value for @text.
Or when XOR is in focus:
There is the COALESCE expression (although not function https://msdn.microsoft.com/en-us/library/ms190349.aspx) test the arguments in order and keep doing it until finds the value not NULL and returns it.
example usage:
SELECT COALESCE(NULL, NULL, 5)--returns 5
In your case :
COALESCE(a.PolicySignedDateTime,aq.Amount) AS 'Signed Premium',
Try this:
But.... ISNULL(a.PolicySignedDateTime, aq.Amount) check if your field is null, so is not null you obtain its value.
So I don't really understand because you want to use another way.