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 July 7th, 2005, 02:11 PM
Authorized User
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default mulitiple field query PLUS

I want to query an Access database through ASP. I want the query to return records based on parameters entered by the user, unless no parameter for a particular field is entered, in which case it would return all records where that field exists.

Example (and I hope this is clear):

The database is a list of documents of county records, containing a document name, a county name, a document summary, etc. I want the user to be able to look up records either by county, or document name, or both. So the query form will request the user to enter a parameter in the appropriate field. If they enter no parameter, the query is to assume all records containing any value for that field are being requested.

Some one suggested the statement below, but I get an
"Invalid use of vertical bars in expression" error.

Anyone know the correct Access syntax?

select * from records
where dName like '%' || nvl('&dName','') || '%'
and county like '%' || nvl('&county','') || '%';

Thanks for your help,


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

Try this.

cn = Your Connection String

dName = request("dName")
County = request("County")

set rs = server.createobject("adodb.recordset")
sql = "select * from records"
if dName <> "" OR County <> "" then
    sql = sql & " where"
    if dName <> "" then
        sql = sql & " dName like '*" & dName & "*'"
    end if
    if dName <> "" AND County <> "" then
        sql = sql & " and"
    end if
    if County <> "" then
        sql = sql & " County like '*" & County & "*'"
    end if
end if
'response.write sql & "<br>"
rs.open sql, cn
if not rs.eof then
    do while not rs.eof
    response.write rs("dName")
end if
set rs = nothing
Old July 14th, 2005, 10:54 AM
Authorized User
Join Date: Oct 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

quote:Originally posted by DaveGerard
 Try this.

Thanks 1024K. This looks very promising.

I was looking for a particular syntax for an Access SQL query that would accomplish the same as the "IF THEN" statements, but perhaps this is the only way to do it with Access?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mulitiple/Nested IIF statements rohit_ghosh Access VBA 3 June 1st, 2007 10:44 AM
Passing Mulitiple pameters to a form query c_olinrb Access 3 January 19th, 2007 03:25 PM
Prevent mulitiple logins in webgarden/farm senario amitjoshipune ASP.NET 1.0 and 1.1 Professional 4 August 18th, 2006 02:21 AM
Help-Query must have at least 1 destination field surajguru Access 4 September 13th, 2005 12:21 PM
Query DateTime Field mtalam Access 5 June 3rd, 2004 06:51 AM

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