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 May 26th, 2005, 11:44 AM
Authorized User
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with whereclause

Hi there

I'm having some problems with a script that is supposed to search a database with optional variables, and output mean values for the selected dataset.

Users can select any combination of 3 drop down boxes in a form. On submit, the following asp page is supposed to only show results from a query generated form this combination.

The 3 variables transfer ok, so I think there might be something weird with my querystring definitions (whereclause):

----------------

degree = Request.Querystring("degree")
unit = Request.Querystring("unit")
year = Request.Querystring("year")

' I have seen the error of my ways and will change this to Request.Form in the next version!

whereclause = "WHERE "

If degree >< "" Then

        whereclause = whereclause & "degree = '" & degree & "' AND "

        End if

If unit >< "" Then
        whereclause = whereclause & "unit = '" & unit & "' AND "

        End if

If year >< "" Then
        whereclause = whereclause & "year = '" & year & "' AND "

        end if

If Right(whereclause,4) = "AND " then
whereclause = Left(whereclause, Len(whereclause) -4)
end if

conn.open conn_str
strsql = "SELECT * FROM IPLUeval " & whereclause & " ORDER BY autonumber "

Set RSEVal = conn.Execute(strsql)
RSEval.Open "IPLUeval", conn_str, adOpenKeyset, adLockOptimistic, adCmdtable

-------------------------------------------

I get an error saying:

"Syntax error in FROM clause.
/sohpnet/evaluation/ipluget.asp, line 47"

which is basically the conn.execute line.

Can anyone see anything weird here? I'm going codeblind!!

Heidi



 
Old May 27th, 2005, 03:22 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Heidi,

Can you Response.Write strsql to the page & post the output, please.

Cheers,

Chris


 
Old May 27th, 2005, 08:23 AM
Authorized User
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris

Thanks for answering.

On a random configuration of the variables, the response.write of strsql is:

SELECT * FROM IPLUeval WHERE degree = 'BSc Podiatry' AND unit = 'IPLU 2' AND year = '2004/2005' ORDER BY autonumber

 
Old May 27th, 2005, 10:16 AM
Authorized User
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Without really having changed anything, I now get the error message

Microsoft JET Database Engine (0x80040E10)
No value given for one or more required parameters.
/sohpnet/evaluation/ipluget.asp, line 47

pointing to the same line as before.
Maybe I should also mention that when I do

'Set RSEVal = conn.Execute(strsql)

The page comes up partially displaying mean values for only the variables that apply to ALL records in the database, but not for the ones that belong to various units alone.

Heidi


 
Old May 27th, 2005, 10:39 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Heidi,

I assume all the fields in your where clause are string types in the db. The sql looks ok to me, so it may be a field or reserved word problem - the field name "year" might cuase problems for some dbs.

Try to isolate which part of the query is causing the issue - run it without any where clause, if that works, try it with each part of the where clause individually e.g.:
Code:
SELECT * FROM IPLUeval WHERE degree = 'BSc Podiatry';
SELECT * FROM IPLUeval WHERE unit = 'IPLU 2'; 
SELECT * FROM year = '2004/2005';
finally add the order by clause. At one of these points you should find the problem.

HTH,

Chris

 
Old June 2nd, 2005, 06:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:If degree >< "" Then
I wonder if that works? Do you mean <> there?

Does YEAR column contain data in '2004/2005' format? Can you mention what datatypes are the degree, unit and year in your table?

_________________________
- Vijay G
Strive for Perfection
 
Old June 8th, 2005, 06:53 AM
Authorized User
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vijay

Sorry about the late response, things got a bit mad here!
--------------------
If degree >< "" Then

I wonder if that works? Do you mean <> there?
-----------------------------------
I've worked with >< "" (as in 'anything BUT') many other scrips that run fine, though I suspect it might be tidier with a NOT here? (Learning as I go along!)

-----------------------------------
Does YEAR column contain data in '2004/2005' format? Can you mention what datatypes are the degree, unit and year in your table?
----------------------------------

Yes, Year is '2004/2005' and will eventually be 2005/2006 etc. I've put this in as a string.

Degree and unit are strings as well.

The data for these valuables are entered through another web form, where the variables are filled from a drop down select menu, so all strings should be ok and identical (have checked this btw).

I think I might be better off scrapping the whole things and starting the page again:(

Heidi







 
Old July 14th, 2005, 11:20 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Did this get resolved yet?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Some problems Sheraz Khan C++ Programming 3 April 11th, 2008 03:42 PM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
more problems Andy122 Dreamweaver (all versions) 5 January 6th, 2005 04:22 PM
whereclause use in a Data Grid acorbo ASP.NET 1.0 and 1.1 Professional 4 August 11th, 2004 07:37 AM
Generate reports from Listbox Or WhereClause help nkrukovsky Access VBA 1 November 6th, 2003 06:36 PM





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