Search Query Problem | |
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 | | | | re: Search Query Problem
SELECT * FROM booking_form WHERE AirportStation LIKE ('%" +
Replace(BookingForm__varAirportStation, "'", "''") + "%')"
should do it
On 2 Mai, 10:01, "Simon Gare" <s...@simongare.comwrote: Quote:
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 | | | | re: Search Query Problem
Simon Gare wrote on 02 mei 2007 in
microsoft.public.inetserver.asp.general: Quote:
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) | | | | re: Search Query Problem
Thanks all worked perfectly.
Simon | | | | re: Search Query Problem
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" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl... Quote:
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 Quote:
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 Quote:
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
>
>
| | | | re: Search Query Problem
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: Quote:
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:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl...
>
>
> > Quote:
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 Quote:
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 Quote:
1 the user has to type in
> Quote:
Heathrow Terminal 1
> Quote:
When really I just want them to type in
> Quote:
Heathrow or even Heath etc.
> > Quote:
SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
> > Quote:
Simon
--
Simon Gare
The Gare Group Limited
> >
- Zitierten Text anzeigen -
| | | | re: Search Query Problem
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" <simon@simongare.comwrote in message
news:ux8L7yJjHHA.4552@TK2MSFTNGP04.phx.gbl... Quote:
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" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl... Quote:
>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 Quote:
>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 Quote:
>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
>>
>>
>
>
| | | | re: Search Query Problem
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" <mgabru@gmail.comwrote in message
news:1178099604.508166.231810@o5g2000hsb.googlegro ups.com... Quote:
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: Quote:
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 Quote: Quote:
place.
All other search criteria is working ok?
Simon
"Simon Gare" <s...@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl... Quote:
have a search.asp page with results.asp page drawing data from an SQL
db, Quote: Quote: Quote:
problem is the user has to type the whole field value into the search
box Quote: Quote:
to Quote:
retrieve the value on results.asp, what I need is to type in just a
few Quote: Quote: Quote:
characters e.g. at the moment to search for all pickups at Heathrow
Terminal Quote:
1 the user has to type in
Quote:
Heathrow Terminal 1
Quote:
When really I just want them to type in
Quote:
Heathrow or even Heath etc.
Quote:
SELECT * FROM booking_form WHERE AirportStation LIKE '" +
Replace(BookingForm__varAirportStation, "'", "''") + "'
Quote:
Simon
--
Simon Gare
The Gare Group Limited
- Zitierten Text anzeigen -
>
>
| | | | re: Search Query Problem
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" <dummy@newsgroups.comwrote in message
news:us2kmEKjHHA.3928@TK2MSFTNGP03.phx.gbl... Quote:
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" <simon@simongare.comwrote in message
news:ux8L7yJjHHA.4552@TK2MSFTNGP04.phx.gbl... Quote:
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
% Quote: Quote:
in
place.
All other search criteria is working ok?
Simon
"Simon Gare" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl... Quote:
Hi,
>
have a search.asp page with results.asp page drawing data from an SQL
db, Quote: Quote: Quote:
problem is the user has to type the whole field value into the search
box Quote: Quote:
to Quote:
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 Quote:
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
>
>
>
>
| | | | re: Search Query Problem
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" <simon@simongare.comwrote in message
news:uYVmhOKjHHA.4676@TK2MSFTNGP02.phx.gbl... Quote:
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" <dummy@newsgroups.comwrote in message
news:us2kmEKjHHA.3928@TK2MSFTNGP03.phx.gbl... Quote:
>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" <simon@simongare.comwrote in message
>news:ux8L7yJjHHA.4552@TK2MSFTNGP04.phx.gbl... Quote:
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
% Quote: Quote:
in
place.
>
All other search criteria is working ok?
>
Simon
>
>
"Simon Gare" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl...
>Hi,
>>
>have a search.asp page with results.asp page drawing data from an SQL
db, Quote: Quote:
>problem is the user has to type the whole field value into the search
box Quote: Quote:
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
>>
>>
>
>
>>
>>
>
>
| | | | re: Search Query Problem
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" <dummy@newsgroups.comwrote in message
news:%231GqxcKjHHA.1900@TK2MSFTNGP04.phx.gbl... Quote:
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" <simon@simongare.comwrote in message
news:uYVmhOKjHHA.4676@TK2MSFTNGP02.phx.gbl... Quote:
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 Quote: Quote:
search page how do I go about that? do I use 2 BETWEEN statements ie
Select * FROM BookingForm WHERE DATE2 BETWEEN
Request.Querystring("DATE2") Quote: Quote:
and BETWEEN Request.Querystring("DATE2")
something like that?
Simon
"Mike Brind" <dummy@newsgroups.comwrote in message
news:us2kmEKjHHA.3928@TK2MSFTNGP03.phx.gbl... Quote:
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 Quote: Quote: Quote:
23:59:59.
>
--
Mike Brind
>
"Simon Gare" <simon@simongare.comwrote in message
news:ux8L7yJjHHA.4552@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 Quote: Quote:
% Quote:
in
place.
All other search criteria is working ok?
Simon
"Simon Gare" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl...
Hi,
>
have a search.asp page with results.asp page drawing data from an
SQL Quote: Quote:
db, Quote:
problem is the user has to type the whole field value into the
search Quote: Quote:
box Quote:
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
>
>
>
>
>
>
| | | | re: Search Query Problem
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" <simon@simongare.comwrote in message
news:uo3XMDMjHHA.1216@TK2MSFTNGP03.phx.gbl... Quote:
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" <dummy@newsgroups.comwrote in message
news:%231GqxcKjHHA.1900@TK2MSFTNGP04.phx.gbl... Quote:
>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" <simon@simongare.comwrote in message
>news:uYVmhOKjHHA.4676@TK2MSFTNGP02.phx.gbl... Quote:
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 Quote: Quote:
search page how do I go about that? do I use 2 BETWEEN statements ie
>
Select * FROM BookingForm WHERE DATE2 BETWEEN
Request.Querystring("DATE2") Quote: Quote:
and BETWEEN Request.Querystring("DATE2")
>
something like that?
>
Simon
>
>
"Mike Brind" <dummy@newsgroups.comwrote in message
news:us2kmEKjHHA.3928@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 Quote: Quote:
>23:59:59.
>>
>--
>Mike Brind
>>
>"Simon Gare" <simon@simongare.comwrote in message
>news:ux8L7yJjHHA.4552@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 Quote: Quote:
%
in
place.
>
All other search criteria is working ok?
>
Simon
>
>
"Simon Gare" <simon@simongare.comwrote in message
news:etrCUBJjHHA.4064@TK2MSFTNGP02.phx.gbl...
>Hi,
>>
>have a search.asp page with results.asp page drawing data from an
SQL Quote: Quote:
db,
>problem is the user has to type the whole field value into the
search Quote: Quote:
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
>>
>>
>
>
>>
>>
>
>
>>
>>
>
>
| | | | re: Search Query Problem
Simon Gare wrote: Quote:
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" | | | | re: Search Query Problem
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcomwrote in message
news:OT9L1pWjHHA.4676@TK2MSFTNGP02.phx.gbl... Quote:
Simon Gare wrote: Quote:
>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. |  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|