Reputation: 137
I'm trying to judge by the name of a car dealership whether a specific car is their brand or not. So with:
select car_make, dealer_name,
case when ('%' || dealer_name || '%') ilike car_make THEN 'OnBrand'
END
from table
Ideally, when searching a car with make Nissan and a dealer named Local Nissan Dealer, the third column would contain OnBrand, but it's returning
Nissan Local Nissan Dealer <null>
Upvotes: 2
Views: 116
Reputation: 16397
This doesn't address why your particular statement isn't working (@user's solution looks good to me), but as an alternative, potentially simpler syntax, what about a regular expression?
select
car_make, dealer_name,
case when dealer_name ~ car_make THEN 'OnBrand' end
from table
Upvotes: 1
Reputation: 1396
You've got your wildcards backwards, you want:
case when dealer_name ilike ('%' || car_make || '%') THEN 'OnBrand'
Upvotes: 2