-
Just a quick question...
I am building an SQL statement to pull all values out of a database that begin with the letter S and over...I wrote something like:
Code:
"SELECT * FROM Database WHERE Partnumber >= 'S'"
However this statement does not include Partnumbers such as S-2000 or even S1234.
Then I thought of adding an ! to the statement so it would include these values:
Code:
"SELECT * FROM Database WHERE Partnumber >= 'S!'"
This would produce the results I wanted....I was just wondering if there was a better way of doing this...without tacking on the !.
-
Use the LIKE statement with a wildcard ( % ) for character searching:
SELECT * FROM Database WHERE Partnumber LIKE 'S%'
-
And, if you're using Access and the "%" wildcard doesn't work, try "*" in its place
-
Try using the like operator with the % and _
the % stands in for a substring of 0 or more characters
example
select * from table where string like 'S%'
the _ stands for exactly one character
example
select * from table where string like 'S__'
I know the statement with like % will probably work for you. I've had that work with Microsoft SQL server. I don't have any experinece using the underscore but from what I've read in SAMS publishing SQL Unleashed that should work.
-
The LIKE statement with operator works nicely to retrieve all of the S items nicely. I thank you all for the help.
I just added it with an OR to my original statement to create the desired results.
Code:
SELECT * FROM Database WHERE Partnumber LIKE 'S%' OR Partnumber >= 'S'
Thanks again :)