Group:  Microsoft Access ยป microsoft.public.access.queries
Thread: String contains query.

String contains query.
david 12/27/2008 2:54:01 AM
How can I create a query that will search for the existance of a char. field
in a string. I'm using Access 2000.

For example:
The char. field would be 'CEC' and the char. var is 'CHL ABC DEF CEC'

Thanks.
Re: String contains query.
"Allen Browne" <AllenBrowne[ at ]SeeSig.Invalid> 12/27/2008 3:31:08 AM
In the Criteria row under the char field, enter:
Like "*"CEC*"

It is possible (depending on settings) you need to use % in place of *.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"david" <david[ at ]discussions.microsoft.com> wrote in message
news:24B96AC7-B7FF-4BF3-868C-A5FD1045FF55[ at ]microsoft.com...
[Quoted Text]
> How can I create a query that will search for the existance of a char.
> field
> in a string. I'm using Access 2000.
>
> For example:
> The char. field would be 'CEC' and the char. var is 'CHL ABC DEF CEC'
>
> Thanks.

RE: String contains query.
Clifford Bass 12/30/2008 4:39:00 AM
Hi David,

If you want to select only those rows where the contents of the char
field are in the string then do this:

SELECT tblSomeTable.CharField
FROM tblSomeTable
WHERE ((("CHL ABC DEF CEC") Like "*" & [CharField] & "*"));

If you want all rows, but want to know if the value of the char field
is in the string then do this:

SELECT OtherFields, CharField, "CHL ABC DEF CEC" Like "*" & [CharField] &
"*" AS FieldInString
FROM tblSomeTable;

The FieldInString will be a boolean values (-1 = true or 0 = false).

Clifford bass

"david" wrote:

[Quoted Text]
> How can I create a query that will search for the existance of a char. field
> in a string. I'm using Access 2000.
>
> For example:
> The char. field would be 'CEC' and the char. var is 'CHL ABC DEF CEC'
>
> Thanks.
RE: String contains query.
david 12/31/2008 1:05:00 AM
Thanks. That's was what I was looking for.
--
david


"Clifford Bass" wrote:

[Quoted Text]
> Hi David,
>
> If you want to select only those rows where the contents of the char
> field are in the string then do this:
>
> SELECT tblSomeTable.CharField
> FROM tblSomeTable
> WHERE ((("CHL ABC DEF CEC") Like "*" & [CharField] & "*"));
>
> If you want all rows, but want to know if the value of the char field
> is in the string then do this:
>
> SELECT OtherFields, CharField, "CHL ABC DEF CEC" Like "*" & [CharField] &
> "*" AS FieldInString
> FROM tblSomeTable;
>
> The FieldInString will be a boolean values (-1 = true or 0 = false).
>
> Clifford bass
>
> "david" wrote:
>
> > How can I create a query that will search for the existance of a char. field
> > in a string. I'm using Access 2000.
> >
> > For example:
> > The char. field would be 'CEC' and the char. var is 'CHL ABC DEF CEC'
> >
> > Thanks.
RE: String contains query.
Clifford Bass 12/31/2008 3:50:03 AM
You are welcome David!

Clifford Bass

"david" wrote:

[Quoted Text]
> Thanks. That's was what I was looking for.
> --
> david

Home | Search | Terms | Imprint
Newsgroups Reader