我需要从Department10中选择名称不包含字符串“LA”的员工。
Select *
From EMP
Where Cod_Dept = 10
答案 0 :(得分:4)
Select *
From EMP
Where Cod_Dept = 10
And Name Not Like '%LA%'
答案 1 :(得分:2)
以下是使用CHARINDEX()
的另一个选项:
SELECT *
FROM EMP
WHERE Cod_Dept = 10
AND CHARINDEX('LA' , Name , 0) = 0;
如果您有Null
值,并且您也希望将其返回:
SELECT *
FROM EMP
WHERE Cod_Dept = 10
AND (CHARINDEX('LA' , Name , 0) = 0) OR (CHARINDEX('LA' , Name , 0) Is Null);
<强> Demo 强>