DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    kari Guest

    select and different search results


    I am trying to search a database and bring back different results
    depends on search criteria.
    I have my sql statement setup to bring back all records between two dates,
    but I also need to bring back all results if no dates were selected, and
    presents "no records" if no records were found between the dates selected.

    here is my sql statement to return results between two dates:
    strSQL = "SELECT rep_id, il_name, type_name, fname, lname, phone, comment,
    state_name " &_
    "FROM inct_rpt, state, il, inct_type " &_
    "WHERE state.state_id=inct_rpt.state_id " &_
    "AND il.il_id=inct_rpt.il_id " &_
    "AND inct_type.inct_type_id=inct_rpt.inct_type_id " &_
    "and inct_rpt.update_date <= '" & request.querystring("before") & "'"
    &_
    "and inct_rpt.update_date > '" & request.querystring("after") & "' " &_
    "ORDER BY inct_rpt.update_date "


  2. #2
    Robert Gelb Guest

    Re: select and different search results

    You should create the SQL dynamically. If the user enters dates, then add
    the date criteria to the SQL statement. If not, then execute without the
    dates criteria and you should get all the data back.

    --
    Robert Gelb
    www.vbRad.com
    Source, Tips, Tricks, Components

    "kari" <kari.l.macko@xo.com> wrote in message
    news:3af9811c$1@news.devx.com...
    >
    > I am trying to search a database and bring back different results
    > depends on search criteria.
    > I have my sql statement setup to bring back all records between two dates,
    > but I also need to bring back all results if no dates were selected, and
    > presents "no records" if no records were found between the dates selected.
    >
    > here is my sql statement to return results between two dates:
    > strSQL = "SELECT rep_id, il_name, type_name, fname, lname, phone, comment,
    > state_name " &_
    > "FROM inct_rpt, state, il, inct_type " &_
    > "WHERE state.state_id=inct_rpt.state_id " &_
    > "AND il.il_id=inct_rpt.il_id " &_
    > "AND inct_type.inct_type_id=inct_rpt.inct_type_id " &_
    > "and inct_rpt.update_date <= '" & request.querystring("before") & "'"
    > &_
    > "and inct_rpt.update_date > '" & request.querystring("after") & "' " &_
    > "ORDER BY inct_rpt.update_date "
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links