3piecechickendinner
3piecechickendinner

Reputation: 43

Issue with CASE statement not giving correct value

I am using the following CASE statement in SQL Developer:

CASE  
  WHEN ([Medication]="N") AND ([Name]="STYMES") AND ([Original Units] IS NOT NULL) THEN "Y" 
  WHEN ([Medication]="N") AND ([Name]="STYMES") AND ([Original Units] IS NULL) THEN "N" 
  WHEN ([Medication]="Y") AND ([Name]="STYMES") AND ([Original Units] IS NOT NULL) THEN "N" 
  WHEN ([Medication]="Y") AND ([Name]="STYMES") AND ([Original Units] IS NULL) THEN "Y" 
END

My results are empty when I should at least get N.

Upvotes: 0

Views: 50

Answers (1)

AHiggins
AHiggins

Reputation: 7219

If all you want is to get an 'N' when your other conditions are not met, you can use the ELSE keyword, as in:

case  
  when ([Medication]="N") AND ([Name]="STYMES") AND([Original Units] is not null) then "Y" 
  when ([Medication]="N") AND ([Name]="STYMES") AND([Original Units] is null) then "N" 
  when ([Medication]="Y") AND ([Name]="STYMES") AND([Original Units] is not null) then "N" 
  when ([Medication]="Y") AND ([Name]="STYMES") AND([Original Units] is null) then "Y" 
  else "N"
end

Upvotes: 1

Related Questions