Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax for 'where field contains 'string'' 1

Status
Not open for further replies.

almoes

Programmer
Joined
Jan 8, 2003
Messages
291
Location
US
Hi all!

I am trying to figure out the proper syntax for the following:

Select * from myDB where myField contains ('181')

I need to retrieve all rows where the field contains 181.
Thanxs.

cheers,
alej
 
Try:
Code:
SELECT  *
  FROM    myDB..myTable
  WHERE   myField [COLOR=maroon]LIKE '%181%'[/color]
This will select all rows where myField contains the string 181 somewhere in the text.

Hope this helps,
John
 
Cool it works! Thanxs!
 
Glad I could help.

A couple of notes to add to this, the % wildcard will substitute any number of characters wherever it is placed, while the _ (underscore) wildcard substitutes a single character.

You can also use sets and ranges of characters by enclosing them in brackets ([ ]).

ex: WHERE SSN LIKE '123-45-[0-9][0-9][0-9][0-9]'
gives all variations of SSN beginning with 123-45- and ensuring that the following characters are actually digits.

John
 
even cooler! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top