For MS SQL Server (T-SQL), there is no support for WHERE a LIKE (b, c, d, e)
or similar. However, here is a work-around that gives you the ability to make the list of patterns dynamic and doesn't force you to resort to "OR-chaining" multiple LIKE
expressions.
declare @Fruits table (Name nvarchar(100));
insert @Fruits (Name)
values
('Apple')
, ('Banana')
, ('Cherry')
, ('Pear')
, ('Strawberry')
, ('Blackberry')
, ('Raspberry')
, ('Pomegranate')
, ('Plantain')
, ('Grape')
, ('Kiwi')
;
-----------------------------------------------------------
-- STATIC - using OR-chaining
-----------------------------------------------------------
select
f.Name
from
@Fruits f
where
f.Name like 'B%'
or f.Name like '%berry'
;
-----------------------------------------------------------
-- DYNAMIC - using EXISTS
-----------------------------------------------------------
select
f.Name
from
@Fruits f
where
exists (
select 1
from (values ('B%'), ('%berry')) v (Pattern)
where f.Name like v.Pattern escape '\'
)
;
Using the "dynamic" style, you could populate a table of patterns elsewhere, dynamically, and with an arbitrary number of patterns, giving you more control and flexibility.