-1

I use SQL inside a 3rd party system (So don't know the type it is) I am trying to make a CASE work on a column using data from 2 more.

I want to display a column call Channel that is calculated using the following logic:

If column O.Test is blank and column o.subsource is not blank, display 'RESEND', otherwise display the value of column o.Source.

This is part of the SQL showing the CASE I wrote to do this:

select
  -- other columns
 (CASE
   WHEN o.Test = NULL AND o.Subsource IS NOT NULL THEN 'RESEND'
   ElSE o.Source
 END) o.Source AS 'Channel',
 -- other columns

The SQL runs with no errors but the output always shows what is in o.Source.

Bohemian
  • 412,405
  • 93
  • 575
  • 722

1 Answers1

0

X = NULL is not equal IS NULL X

Check this question,

SQL is null and = null

change this statement "o.Test = NULL" instead of "o.Test IS NULL"

G.Guvenal
  • 149
  • 7
  • Thanks. I have done that and RESEND replaces data in Column 3 now for When Column1 is Blank (null) and Column 2 is not blank (not null) (which is great and part 1 of what I need) - But it also does it when both Column 1 and 2 are blank. If Column 1 and 2 are blank I need the data inside Column 3 to remain as it is and not be replaced by RESEND. Hope I make sense!!!! – Catrina Field Mar 18 '22 at 20:02
  • @CatrinaField what is the name of your "column 3"? "blank" means the empty string `''`, not `null`? Please don't use the word "blank" when you mean "null" - they re different things. Also, don't change the question, which has been answered (ie the syntax `x = null` is *never* true). If you have additional requirements, ask a new question. – Bohemian Mar 18 '22 at 20:17