在某些情况下熟悉SQL Server 通配符的使用可以帮助我们简单的解决很多问题。
--使用_运算符查找Person表中以an结尾的三字母名字USEAdventureWorks2012;GOSELECT FirstName, LastNameFROM Person.PersonWHERE FirstName LIKE'_an'ORDER BY FirstName; ---使用[^]运算符在Contact表中查找所有名字以Al开头且第三个字母不是字母a的人USEAdventureWorks2012;GOSELECT FirstName, LastNameFROM Person.PersonWHERE FirstName LIKE'Al[^a]%'ORDER BY FirstName; ---使用[]运算符查找其地址中有四位邮政编码的所有Adventure Works雇员的ID和姓名USEAdventureWorks2012;GOSELECT e.BusinessEntityID, p.FirstName, p.LastName, a.PostalCodeFROMHumanResources.EmployeeAS eINNER JOIN Person.PersonAS pON e.BusinessEntityID= p.BusinessEntityIDINNER JOIN Person.BusinessEntityAddressAS eaON e.BusinessEntityID=ea.BusinessEntityIDINNER JOIN Person.AddressAS aON a.AddressID= ea.AddressIDWHERE a.PostalCodeLIKE'[0-9][0-9][0-9][0-9]';
结果集:
结果集:
name -------------------- ------kevin Eng刘 CNkevin刘 Eng&CN (3 row(s) affected)