0

My query:

case 
   when upper(a.camp_name) like "%Event%" and (upper(a.camp_name) not like "%Event-WBR%" or upper(a.camp_name) not like "%Event-Webinar%") THEN "Field"
   else "Demand"
end as Tactic

Desired Output:

Event-WBR = Demand
Event = Field

Actual Output:

Event-WBR = Field
Event = Field
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
RashItIs
  • 87
  • 1
  • 1
  • 10

2 Answers2

0

Actually you should replace the 'or' with 'and'

case 
       when upper(a.camp_name) like "%Event%" and (upper(a.camp_name) not like "%Event-WBR%" and upper(a.camp_name) not like "%Event-Webinar%") THEN "Demand"
       else "Field"
    end as Tactic

But here another 2 other options:

If you only want to do for the word 'Event', you can do something like this

case 
   when upper(a.camp_name) like "%Event" and (upper(a.camp_name) not like "%Event-WBR%" or upper(a.camp_name) not like "%Event-Webinar%") THEN "Demand"
   else "Field"
end as Tactic

If you want to exclude these 2 words only, you can do like this.

case 
   when upper(a.camp_name) like "%Event-WBR%" or (upper(a.camp_name) like "%Event-Webinar%" THEN "Field"
   else "Demand"
end as Tactic
sicKo
  • 1,241
  • 1
  • 12
  • 35
0

You can use two whens :

(case when (upper(a.camp_name) not like "%Event-WBR%" or 
            upper(a.camp_name) not like "%Event-Webinar%"
           ) then 'Event'
      when upper(a.camp_name) like "%Event%" then 'Event'
      else 'Deman'
 end) as tactic
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52