|
-
Aug 15th, 2000, 09:57 AM
#1
Thread Starter
Lively Member
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 !.
-
Aug 15th, 2000, 11:13 AM
#2
Guru
Use the LIKE statement with a wildcard ( % ) for character searching:
SELECT * FROM Database WHERE Partnumber LIKE 'S%'
-
Aug 15th, 2000, 11:17 AM
#3
Frenzied Member
And, if you're using Access and the "%" wildcard doesn't work, try "*" in its place
-
Aug 15th, 2000, 11:17 AM
#4
Member
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.
-
Aug 15th, 2000, 12:51 PM
#5
Thread Starter
Lively Member
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 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|