"query contains" help please

D

David

Hi,

I'd like to adapt the query below to select records only if the Title field
contains the string "Book" (as an example).

I'd also like to use a different variant of the query elsewhere to select
all records where the Title field does not contain the string "Book".

I know my question sounds dumb to many, but I haven't worked with .ASP in a
while, and don't know how to put "Contains" and "Doesn't contain" in a
query, and can't seem to find this info easily at aspin.com

Many thanks for assistance.

David

set rsData = MyConn.execute("select URL,Counter,Title from HitTable ORDER BY
Counter DESC")
arData = rsData.getrows
 
R

Ray at

David said:
Hi,

I'd like to adapt the query below to select records only if the Title field
contains the string "Book" (as an example).

What kind of database?

select URL,Counter,Title from HitTable WHERE Title LIKE '%Book%' ORDER BY
Counter DESC



I'd also like to use a different variant of the query elsewhere to select
all records where the Title field does not contain the string "Book".

select URL,Counter,Title from HitTable WHERE Title NOT LIKE '%Book%' ORDER
BY Counter DESC


I know my question sounds dumb to many, but I haven't worked with .ASP in a
while, and don't know how to put "Contains" and "Doesn't contain" in a
query, and can't seem to find this info easily at aspin.com

It's not dumb!

Ray at work
 
A

Alex Goodey

This is more to do with T-SQL statements rather than asp, to have a
condition where a string must contain somethin you use LIKE

set rsData = MyConn.execute("select URL,Counter,Title from HitTable WHERE
Title LIKE '%Book%' ORDER BY Counter DESC")

The % marks around Book, state that Book can be located anywhere in the
string so a book called aaaaBookaaa would be returned as would aaaaBook and
Bookaaa

If you left out the preceding % like this 'Book%' then only 'Bookaaa' would
be returned
 

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

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top