By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Search Query Problem

P: n/a
Hi,

have a search.asp page with results.asp page drawing data from an SQL db,
problem is the user has to type the whole field value into the search box to
retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk
May 2 '07 #1
Share this Question
Share on Google+
14 Replies


P: n/a
SELECT * FROM booking_form WHERE AirportStation LIKE ('%" +
Replace(BookingForm__varAirportStation, "'", "''") + "%')"

should do it

On 2 Mai, 10:01, "Simon Gare" <s...@simongare.comwrote:
Hi,

have a search.asp page with results.asp page drawing data from an SQL db,
problem is the user has to type the whole field value into the search box to
retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'

anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk

May 2 '07 #2

P: n/a
Simon Gare wrote on 02 mei 2007 in
microsoft.public.inetserver.asp.general:
Hi,

have a search.asp page with results.asp page drawing data from an SQL
db, problem is the user has to type the whole field value into the
search box to retrieve the value on results.asp, what I need is to
type in just a few characters e.g. at the moment to search for all
pickups at Heathrow Terminal 1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
With "LIKE" you only would have to add a wildcard character.

SELECT * FROM booking_form WHERE AirportStation LIKE '" +_
yourSearchInput + "%" + "'

=============

"Heathrow Te" + "%"

will select:

Heathrow Terminal 1
Heathrow Terminal 2
Heathrow Terminal 3
Heathrow Terminal 4
Heathrow Terminal 5 [?]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 2 '07 #3

P: n/a
Thanks all worked perfectly.

Simon
May 2 '07 #4

P: n/a
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the % in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,

have a search.asp page with results.asp page drawing data from an SQL db,
problem is the user has to type the whole field value into the search box
to
retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk


May 2 '07 #5

P: n/a
i am not sure but i think that like is not working on data columns ...
you should be fine with
WHERE datCol = '02/05/2007'

On 2 Mai, 11:28, "Simon Gare" <s...@simongare.comwrote:
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the % in
place.

All other search criteria is working ok?

Simon

"Simon Gare" <s...@simongare.comwrote in message

news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,
have a search.asp page with results.asp page drawing data from an SQL db,
problem is the user has to type the whole field value into the search box
to
retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in
Heathrow Terminal 1
When really I just want them to type in
Heathrow or even Heath etc.
Query below
SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?
Simon
--
Simon Gare
The Gare Group Limited
website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

May 2 '07 #6

P: n/a
Michal is correct. LIKE doesn't work with datetime. You will have to use
Between to find datetimes in a range. If you want to find items with
today's date, your range will be from 02/05/2007 00:00:00 to 02/05/2007
23:59:59.

--
Mike Brind

"Simon Gare" <si***@simongare.comwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the %
in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
>Hi,

have a search.asp page with results.asp page drawing data from an SQL db,
problem is the user has to type the whole field value into the search box
to
>retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
>1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk



May 2 '07 #7

P: n/a
but we retrieve the value from a querystring that is entered on a search
page

BookingForm__varID = Request.Querystring DATE2

TimeOfBooking LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%'

but returns no values doesn't matter what format you put it in either, will
retrieve values when the format is correct though which is no good to us.

02/05/2007 11:02:35 etc


"michal" <mg****@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
i am not sure but i think that like is not working on data columns ...
you should be fine with
WHERE datCol = '02/05/2007'

On 2 Mai, 11:28, "Simon Gare" <s...@simongare.comwrote:
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the
% in
place.

All other search criteria is working ok?

Simon

"Simon Gare" <s...@simongare.comwrote in message

news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,
have a search.asp page with results.asp page drawing data from an SQL
db,
problem is the user has to type the whole field value into the search
box
to
retrieve the value on results.asp, what I need is to type in just a
few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in
Heathrow Terminal 1
When really I just want them to type in
Heathrow or even Heath etc.
Query below
SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?
Simon
--
Simon Gare
The Gare Group Limited
website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk- Zitierten Text ausblenden -
- Zitierten Text anzeigen -


May 2 '07 #8

P: n/a
ok, so if I want to find all entries an the results page with the date
specified in the querystring which is entered manually by the user on the
search page how do I go about that? do I use 2 BETWEEN statements ie

Select * FROM BookingForm WHERE DATE2 BETWEEN Request.Querystring("DATE2")
and BETWEEN Request.Querystring("DATE2")

something like that?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
Michal is correct. LIKE doesn't work with datetime. You will have to use
Between to find datetimes in a range. If you want to find items with
today's date, your range will be from 02/05/2007 00:00:00 to 02/05/2007
23:59:59.

--
Mike Brind

"Simon Gare" <si***@simongare.comwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the
%
in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,

have a search.asp page with results.asp page drawing data from an SQL
db,
problem is the user has to type the whole field value into the search
box
to
retrieve the value on results.asp, what I need is to type in just a few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk



May 2 '07 #9

P: n/a
Simon Gare wrote:
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00
http://www.aspfaq.com/show.asp?id=2313 vbscript
http://www.aspfaq.com/show.asp?id=2040 help with dates
http://www.aspfaq.com/show.asp?id=2260 dd/mm/yyy confusion
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
May 2 '07 #10

P: n/a
If the likely value of Request.QueryString("yourdate") is eg 02/05/2007,
then the query would be

Select * From BookingForm Where datefield Between '" &
Request.QueryString("yourdate") & " 00:00:00' AND '" &
Request.QueryString("yourdate") & " 23:59:59'

--
Mike

"Simon Gare" <si***@simongare.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
ok, so if I want to find all entries an the results page with the date
specified in the querystring which is entered manually by the user on the
search page how do I go about that? do I use 2 BETWEEN statements ie

Select * FROM BookingForm WHERE DATE2 BETWEEN Request.Querystring("DATE2")
and BETWEEN Request.Querystring("DATE2")

something like that?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
>Michal is correct. LIKE doesn't work with datetime. You will have to
use
Between to find datetimes in a range. If you want to find items with
today's date, your range will be from 02/05/2007 00:00:00 to 02/05/2007
23:59:59.

--
Mike Brind

"Simon Gare" <si***@simongare.comwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have the
%
in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,

have a search.asp page with results.asp page drawing data from an SQL
db,
>problem is the user has to type the whole field value into the search
box
to
retrieve the value on results.asp, what I need is to type in just a
few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk




May 2 '07 #11

P: n/a
Thanks Mike, works ok when looking for a date but upsets the other search
criteria, SQL Query looks at 1 value in the querystring and compares across
many fields
SELECT * FROM booking_form WHERE ID LIKE '" + Replace(BookingForm__varID,
"'", "''") + "' OR TimeOfBooking BETWEEN '" + Replace(BookingForm__varID,
"'", "''") + " 00:00:00' AND '" + Replace(BookingForm__varID, "'", "''") + "
23:59:59' OR PAX_NAME1 LIKE '%" + Replace(BookingForm__varID, "'", "''") +
"%' OR COLL_STREET LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%'
OR COLL_POST_CODE LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%' OR
MOBILE_NO LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%' OR
COLL_BUILDING_NAME_NO LIKE '%" + Replace(BookingForm__varID, "'", "''") +
"%' ORDER BY TimeOfBooking DESC"
When i put in the date it works fine but if i put in a name which looks in
PAX_NAME1 field the error reads

Syntax error converting datetime from character string.
Any ideas?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If the likely value of Request.QueryString("yourdate") is eg 02/05/2007,
then the query would be

Select * From BookingForm Where datefield Between '" &
Request.QueryString("yourdate") & " 00:00:00' AND '" &
Request.QueryString("yourdate") & " 23:59:59'

--
Mike

"Simon Gare" <si***@simongare.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
ok, so if I want to find all entries an the results page with the date
specified in the querystring which is entered manually by the user on
the
search page how do I go about that? do I use 2 BETWEEN statements ie

Select * FROM BookingForm WHERE DATE2 BETWEEN
Request.Querystring("DATE2")
and BETWEEN Request.Querystring("DATE2")

something like that?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
Michal is correct. LIKE doesn't work with datetime. You will have to
use
Between to find datetimes in a range. If you want to find items with
today's date, your range will be from 02/05/2007 00:00:00 to
02/05/2007
23:59:59.

--
Mike Brind

"Simon Gare" <si***@simongare.comwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have
the
%
in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,

have a search.asp page with results.asp page drawing data from an
SQL
db,
problem is the user has to type the whole field value into the
search
box
to
retrieve the value on results.asp, what I need is to type in just a
few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk





May 2 '07 #12

P: n/a
Deary me. Just a glance at that SQL string makes me faint.

Try taking all those replace operations out of the concatention. Do them
before you build your SQL string. Better still, use parameter markers or
stored procedures.

Mike

"Simon Gare" <si***@simongare.comwrote in message
news:uo**************@TK2MSFTNGP03.phx.gbl...
Thanks Mike, works ok when looking for a date but upsets the other search
criteria, SQL Query looks at 1 value in the querystring and compares
across
many fields
SELECT * FROM booking_form WHERE ID LIKE '" +
Replace(BookingForm__varID,
"'", "''") + "' OR TimeOfBooking BETWEEN '" + Replace(BookingForm__varID,
"'", "''") + " 00:00:00' AND '" + Replace(BookingForm__varID, "'", "''") +
"
23:59:59' OR PAX_NAME1 LIKE '%" + Replace(BookingForm__varID, "'", "''") +
"%' OR COLL_STREET LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%'
OR COLL_POST_CODE LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%'
OR
MOBILE_NO LIKE '%" + Replace(BookingForm__varID, "'", "''") + "%' OR
COLL_BUILDING_NAME_NO LIKE '%" + Replace(BookingForm__varID, "'", "''") +
"%' ORDER BY TimeOfBooking DESC"
When i put in the date it works fine but if i put in a name which looks in
PAX_NAME1 field the error reads

Syntax error converting datetime from character string.
Any ideas?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>If the likely value of Request.QueryString("yourdate") is eg 02/05/2007,
then the query would be

Select * From BookingForm Where datefield Between '" &
Request.QueryString("yourdate") & " 00:00:00' AND '" &
Request.QueryString("yourdate") & " 23:59:59'

--
Mike

"Simon Gare" <si***@simongare.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
ok, so if I want to find all entries an the results page with the date
specified in the querystring which is entered manually by the user on
the
search page how do I go about that? do I use 2 BETWEEN statements ie

Select * FROM BookingForm WHERE DATE2 BETWEEN
Request.Querystring("DATE2")
and BETWEEN Request.Querystring("DATE2")

something like that?

Simon
"Mike Brind" <du***@newsgroups.comwrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
Michal is correct. LIKE doesn't work with datetime. You will have to
use
Between to find datetimes in a range. If you want to find items with
today's date, your range will be from 02/05/2007 00:00:00 to
02/05/2007
>23:59:59.

--
Mike Brind

"Simon Gare" <si***@simongare.comwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
Just came across a problem, when searching the date field it returns
nothing, current entry format is

dd/mm/yyyy hh:mm:ss
02/05/2007 10:26:00

when I search for 02/05/2007 nothing is returned even though I have
the
%
in
place.

All other search criteria is working ok?

Simon
"Simon Gare" <si***@simongare.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi,

have a search.asp page with results.asp page drawing data from an
SQL
db,
problem is the user has to type the whole field value into the
search
box
to
retrieve the value on results.asp, what I need is to type in just a
few
characters e.g. at the moment to search for all pickups at Heathrow
Terminal
1 the user has to type in

Heathrow Terminal 1

When really I just want them to type in

Heathrow or even Heath etc.

Query below

SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
anyone help?

Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk






May 3 '07 #13

P: n/a
Simon Gare wrote:
Thanks Mike, works ok when looking for a date but upsets the other
search criteria, SQL Query looks at 1 value in the querystring and
compares across many fields
Well, forget this idea. it cannot work. You cannot search a column with one
datatype using a value with an incompatible datatype. You will have to look
at the value supplied by the user and decide which columns to include in the
WHERE clause.
Personally, I would provide the user a means of indicating what type of data
is being supplied (a dropdown, or some radio buttons). In the responding
page, first validate that the data supplied for the search can be coerced
into the selected data type, returning an error to the user if it cannot be.
Once you have determined that the user has supplied compatible data and data
type, build your WHERE clause only including the columns that are compatible
with the selected data type.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
May 3 '07 #14

P: n/a

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
Simon Gare wrote:
>Thanks Mike, works ok when looking for a date but upsets the other
search criteria, SQL Query looks at 1 value in the querystring and
compares across many fields
Well, forget this idea. it cannot work. You cannot search a column with
one datatype using a value with an incompatible datatype.
I was so distracted by all the Replace() operations going on, I missed the
fact that Simon was using the same value for all the filters.
May 3 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.