Connecting Tech Pros Worldwide Help | Site Map

If criteria is Null then show all.

  #1  
Old March 7th, 2007, 08:45 PM
valntyn via DBMonster.com
Guest
 
Posts: n/a
I have an .asp page that passes four variables to another .asp page by using
an HTML form. A SQL query then runs against an Access database using those
four variables. The variables are: "cnty", "rte", "bgn", and "nd".

My current SQL statement is as follows:

SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND Route='" &
rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn & ""

This works just fine, but I would like to add the ability to make "nd" and
"bgn" Null (leave those fields blank on the HTML form), and then return all
records that match the "cnty" and "rte" variables. I have an SQL Query in
the Access database that does this perfectly but I'm having trouble getting
the same functionality on the web.

Any help is greatly appreciated!

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....neral/200611/1

  #2  
Old March 9th, 2007, 02:35 PM
Lew
Guest
 
Posts: n/a

re: If criteria is Null then show all.


valntyn via DBMonster.com wrote:
Quote:
I have an .asp page that passes four variables to another .asp page by using
an HTML form. A SQL query then runs against an Access database using those
four variables. The variables are: "cnty", "rte", "bgn", and "nd".
>
My current SQL statement is as follows:
>
SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND Route='" &
rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn & ""
>
This works just fine, but I would like to add the ability to make "nd" and
"bgn" Null (leave those fields blank on the HTML form), and then return all
records that match the "cnty" and "rte" variables. I have an SQL Query in
the Access database that does this perfectly but I'm having trouble getting
the same functionality on the web.
Pseudocode:

if ( empty( cnty ))
SQL = "SELECT * FROM Construction WHERE Route='" & rte & "' AND Begin<=" &
nd & " AND Ending>=" & bgn

else
SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND Route='"
& rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn

-- Lew
  #3  
Old March 9th, 2007, 02:35 PM
Lew
Guest
 
Posts: n/a

re: If criteria is Null then show all.


Lew wrote:
Quote:
valntyn via DBMonster.com wrote:
Quote:
>I have an .asp page that passes four variables to another .asp page by
>using
>an HTML form. A SQL query then runs against an Access database using
>those
>four variables. The variables are: "cnty", "rte", "bgn", and "nd".
>>
>My current SQL statement is as follows:
>>
>SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND
>Route='" &
>rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn & ""
>This works just fine, but I would like to add the ability to make "nd"
>and
>"bgn" Null (leave those fields blank on the HTML form), and then
>return all
>records that match the "cnty" and "rte" variables. I have an SQL
>Query in
>the Access database that does this perfectly but I'm having trouble
>getting
>the same functionality on the web.
Sorry, I focused on the wrong variable:

Pseudocode:

if ( empty( bgn ) OR empty( nd ) )
SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND
Route='" & rte & "' "

else
SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND
Route='" & rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn

-- Lew
  #4  
Old March 9th, 2007, 04:35 PM
HansH
Guest
 
Posts: n/a

re: If criteria is Null then show all.


"valntyn via DBMonster.com" <u29706@uweschreef in bericht
news:6ed7203954842@uwe...
Quote:
My current SQL statement is as follows:
>
SQL = "SELECT * FROM Construction WHERE County='" & cnty & "' AND Route='"
&
rte & "' AND Begin<=" & nd & " AND Ending>=" & bgn & ""
>
This works just fine, but I would like to add the ability to make "nd" and
"bgn" Null (leave those fields blank on the HTML form), and then return
all
records that match the "cnty" and "rte" variables. I have an SQL Query in
the Access database that does this perfectly but I'm having trouble
getting
the same functionality on the web.
>
How about ...
FLAG = empty( bgn ) OR empty( nd ) ? 'true' : 'false';
SQL = "SELECT * FROM Construction WHERE County='" & cnty
& "' AND Route='" & rte
& "' AND ( " & FLAG
& " or Begin<=0" & nd & " AND Ending>=0" & bgn & " )"

Note: assuming numerical input for nd and bgn, thus prepending 0.

Leaving out vowels in variable names ... Hebrew background?

HansH


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional "Is Null" Query Criteria veaux@aol.com answers 1 June 27th, 2008 08:26 PM
How to list records in correspondence table Where [OutDate] Is Null AND [OutType]='06' ? MLH answers 7 January 3rd, 2007 08:25 PM
is null and Asterisk wildcard eddie.holder@mousetraining.com answers 7 June 16th, 2006 11:05 PM
is null not working for date/time jno.aubrey@gmail.com answers 4 March 17th, 2006 01:15 PM