How to PARSE using SQL?

T

Tim McGavin

I am trying to parse a string something like this...

SELECT * from Table1 WHERE "Sarah" EXISTS ANYWHERE in "Name" Column.

I would like the record to be selected if the Name column said "Sarah" and
also if the name column said "xSarahx".

I am doing this in MS Access 2003 and I realize that I could dump the entire
table in a recordset but I am trying to avoid that if possible.

Please help,

Thanks
 
A

Albert D. Kallal

Try:


SELECT * from Table1 WHERE PersonName like "*Sarah*"


So, you can use while cards. To find all names that start with the letter
"s", you could go:


SELECT * from Table1 WHERE PersonName like "S*"

and, all names that end in the letter s

SELECT * from Table1 WHERE PersonName like "*S"


Note that for following two cases, indexing CAN NOT be used:

eg:
"*s" (ending in s)
and
for "*s*" (a s "anywhere" in the field)


However, for

"s*" (starting in s) high speed indexing can be used.

So, you have lot of records, when indexing can't be used, then a full table
scan occurs, and that can cause a lot of data to be transferred if your
running this in a multi-user situation (network involved).
 
P

pietlinden

I am trying to parse a string something like this...

SELECT * from Table1 WHERE "Sarah" EXISTS ANYWHERE in "Name" Column.

I would like the record to be selected if the Name column said "Sarah" and
also if the name column said "xSarahx".

I am doing this in MS Access 2003 and I realize that I could dump the entire
table in a recordset but I am trying to avoid that if possible.

Please help,

Thanks

SELECT * FROM Table1 WHERE Name LIKE "*Sarah*";
 
D

Douglas J. Steele

First, Name is a bad choice for a field name: it's a reserved word, and
should never be used for your own purposes. If you cannot (or will not)
rename the field, at least put square brackets around it. (For a good
discussion of what names to avoid, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html)

If you're using DAO, your SQL should be something like:

SELECT * from Table1 WHERE NameFIeld Like "*Sarah*"

For ADO, you need

SELECT * from Table1 WHERE NameFIeld Like "%Sarah%"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top