Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table employee in that Name is a column.

I want to get all employees who are having only one word in their name. Like Ram,john not like Ram charan, John smth..
Posted
Updated 22-Aug-13 2:03am
v2

Assume the words are got separated by space, then you can use:
SQL
WHERE Name NOT LIKE '%[^ ]% [^ ]%'

It will return set of names not having a space between other words.
 
Share this answer
 
v2
Comments
Maciej Los 22-Aug-13 9:26am    
+5
Solution 1 and 2 are very good.

Another way is to use CHARINDEX[^] function.

SQL
SELECT LTRIM(RTRIM([Name])) AS [Name]
FROM TableName
WHERE CHARINDEX(' ', LTRIM(RTRIM([Name]))) = 0


Note:
LTRIM[^] and RTRIM[^] function is used to remove leading and ending spaces.
 
Share this answer
 
Comments
fjdiewornncalwe 22-Aug-13 9:53am    
My 5.
Maciej Los 22-Aug-13 14:07pm    
Thank you, Marcus ;)
Thanks7872 22-Aug-13 11:33am    
I like this way. Upvoted.
gvprabu 22-Aug-13 11:47am    
My 5+ :-)
Maciej Los 22-Aug-13 14:08pm    
Thank you, Gopal ;)
Refer this link

SQL LIKE Operator[^]

Regards..:)
 
Share this answer
 
Comments
Maciej Los 22-Aug-13 9:26am    
+5
Thanks7872 22-Aug-13 11:32am    
Thanks Maciej.

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