Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!
I have created such table:
CREATE TABLE Person
         (
             PersonID  uniqueidentifier,
             FirstName  VARCHAR(80),
             LastName   VARCHAR(100),
         );


I want to find all the persons whose lastname has no letter "a" in their lastnames. I query:

SELECT FirstName, LastName
         FROM Person
         WHERE   LastName NOT LIKE '%a%';

///// It works fine
But when i quey like that

SELECT  FirstName, LastName
         FROM   Person
         WHERE   LastName  LIKE '%[^a]%';


It doesn't work - I see the lastnames with an "a" letter....
What's the difference between these two queries??

One more question, how to select all the persons whose
last name has ONLY ONE "a" letter, ONLY TWO "a" letters, ....
Posted
Updated 30-Mar-10 3:20am
v2

The second query returns all names with contains a letter which is no 'a'. So 'Dave' contains 3 letter which ar no 'a', so it will show up in the results.
 
Share this answer
 
Like does not use regular expression syntax, that's why the second one fails to get the expected results

[edit]
You are right about like does not support regular expression. But the syntac in the second SQL query is good.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900