Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2007, 03:23 AM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default SELECT * BETWEEN

Hello,
I am trying to select a range of values from a table called Codes. The values are passed from two input boxes on a form.
I am sooooooooooooooo close but sooooooooooooooooooooooo far away. I know the problems is in the request.form() part of my code. If I insert numbers in place of the request.form() it returns the correct data. Code is defined as a number in the database (Access 2000)

This is the formula for my logic
SELECT "column_name" FROM "table_name"WHERE "column_name" BETWEEN 'value1' AND 'value2'
************************************************** ***********

qry = "SELECT * FROM LA_Codes WHERE Code BETWEEN 10021 AND 10071 "
This works but I need the user to enter the data in a form to search for.
************************************************** ************************************************** **


line 21
"SELECT * FROM LA_Codes "WHERE Code BETWEEN request.form("searchCode2") AND request.form("searchCode3")

Generates this error:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/remmdconnect.asp, line 21
qry = "SELECT * FROM LA_Codes "WHERE Code BETWEEN request.form("searchCode2") AND request.form("searchCode3")
-------------------------------^
************************************************** ************************************************** *********************************
dim code1=request.form("searchCode2")
dim code2=request.form("searchCode3")
line 21
qry = "SELECT * FROM LA_Codes WHERE Code BETWEEN code1 AND code2 "
line 22
Set oRS = oConn.Execute(qry)

Generates this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
/remmdconnect.asp, line 22
************************************************** ************************************************** *****************
line21
qry = "SELECT * FROM LA_Codes WHERE Code BETWEEN 'code1' AND 'code2' "
line 22
Set oRS = oConn.Execute(qry)
Generates this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/remmdconnect.asp, line 22
************************************************** ************************************************** *****************
"SELECT * FROM LA_Codes WHERE Code BETWEEN & request.form('searchCode2') AND request.form('searchCode3') "
Generates this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Code BETWEEN & request.form('searchCode2') AND request.form('searchCode3')'.
/remmdconnect.asp, line 22

Can someone point me in the right direction.
thank you
dink
 
Old January 21st, 2007, 09:28 AM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dink,

Try the following:

code1=request.form("searchCode2")
code2=request.form("searchCode3")

qry = "SELECT * FROM LA_Codes WHERE Code BETWEEN '" & code1 & "' AND '" & code2 & "'"

Be sure to include the spaces after the BETWEEN and around the AND so things don't run together.

Hope this helps,
David


 
Old January 21st, 2007, 03:28 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dave,
I tried:
qry = "SELECT * FROM LA_Codes WHERE Code BETWEEN '" & code1 & "' AND '" & code2 & "'"

It generated this error?

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/remmdconnect.asp, line 22

dink
 
Old January 21st, 2007, 04:15 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For one thing you will want to get rid of the single quotes.
I assume the datatype of the Code column is numeric.

Woody Z
http://www.learntoprogramnow.com
 
Old January 21st, 2007, 04:26 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks woodyz,
taking out the single quotes did the trick!
Thank you!!!
dink
 
Old January 21st, 2007, 09:12 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No prob. Be sure to thank David as well, as he did a good job in showing your basic issue - I just fine tuned it.

Woody Z
http://www.learntoprogramnow.com
 
Old January 21st, 2007, 09:17 PM
Authorized User
 
Join Date: Jan 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I also want to thank you David!
I could not have resolved this problem without the help of you both.
thank you!
dink





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
select="node1", select="node2"... Baldo XSLT 7 March 12th, 2004 10:38 AM
Select Within A Select Problem vinyl-junkie Classic ASP Databases 6 June 7th, 2003 04:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.