Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Dasman
Yak Posting Veteran
79 Posts |
Posted - 2014-03-18 : 20:04:54
|
I have 91 records in a database but this query below yields 90:Select * From TableNameWhere CustomerName LIKE "% %";This returns all but one customer name that two worded names like Jim Smith.Can I do a opposite of this query to find the one customer that only has one word in his name?In general my more conceptual question is: can I run a query to find the opposite of my condition. or to reveal the records that dont fufill a condition?Thanks for your time in reading this post! :)==========================Pain is Weakness Leaving the Body. |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2014-03-18 : 20:40:20
|
Do you mean following?SELECT *FROM TableNameWHERE CustomerName NOT LIKE '% %'--NOT means oppositeorSELECT *FROM TableNameWHERE PATINDEX('% %', CustomerName) = 0--PATINDEX() = 0 means NOT MATCH#CAUTION : NULL record(s) cannot find each queries, so not completery opposite.If you need that, CustomerName column is nullable, add clause to queries like following.SELECT *FROM TableNameWHERE CustomerName NOT LIKE '% %'OR CustomerName IS NULLSELECT *FROM TableNameWHERE PATINDEX('% %', CustomerName) = 0OR CustomerName IS NULL-------------------------------------From JapanSorry, my English ability is limited. |
 |
|
|
|
|