Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > If criteria is Null then show all.
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 3rd September 01:50
valntyn via dbmonster.com
External User
 
Posts: 1
Default If criteria is Null then show all.



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
  Reply With Quote


 


2 3rd September 01:50
lew
External User
 
Posts: 1
Default If criteria is Null then show all.



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
  Reply With Quote


 


3 3rd September 01:50
lew
External User
 
Posts: 1
Default If criteria is Null then show all.


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
  Reply With Quote
4 15th September 21:40
hansh
External User
 
Posts: 1
Default If criteria is Null then show all.


"valntyn via DBMonster.com" <u29706@uwe> schreef in bericht
news:6ed7203954842@uwe...


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
  Reply With Quote
Reply


Thread Tools
Display Modes




666