在SQL Server上使用正则表达式而不是组合两个LIKE语句

时间:2021-10-11 11:05:33

Is there a way I can use regular expression to avoid a UNION of two LIKE statements? for eg: i have the following

有没有办法可以使用正则表达式来避免两个LIKE语句的UNION?例如:我有以下内容

SELECT NAME FROM EMPLOYEE WHERE NAME LIKE 'Adam%'
UNION
SELECT NAME FROM EMPLOYEE WHERE NAME LIKE 'Bob%' 

I don't want to use a UNION and combine the two select statements into one using regular expression. Please help with regex solution or an alternate solution. thanks in advance

我不想使用UNION并使用正则表达式将两个select语句组合成一个。请帮助使用正则表达式解决方案或备用解决方案。提前致谢

2 个解决方案

#1


3  

 SELECT NAME FROM EMPLOYEE WHERE NAME LIKE 'Bob%' OR NAME LIKE 'Adam%'

should work just fine.

应该工作得很好。

#2


0  

Well, If you can't use "OR", use "And" instead:

好吧,如果你不能使用“或”,请使用“和”代替:

Condition1 OR Condition <=> NOT( NOT(Condition1) AND NOT(Condition2) )

Condition1 OR Condition <=> NOT(NOT(Condition1)AND NOT(Condition2))

#1


3  

 SELECT NAME FROM EMPLOYEE WHERE NAME LIKE 'Bob%' OR NAME LIKE 'Adam%'

should work just fine.

应该工作得很好。

#2


0  

Well, If you can't use "OR", use "And" instead:

好吧,如果你不能使用“或”,请使用“和”代替:

Condition1 OR Condition <=> NOT( NOT(Condition1) AND NOT(Condition2) )

Condition1 OR Condition <=> NOT(NOT(Condition1)AND NOT(Condition2))