dbTalk Databases Forums  

If criteria is Null then show all.

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss If criteria is Null then show all. in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
valntyn via DBMonster.com
 
Posts: n/a

Default If criteria is Null then show all. - 03-07-2007 , 03:33 PM






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  
Old   
Lew
 
Posts: n/a

Default Re: If criteria is Null then show all. - 03-09-2007 , 09:23 AM






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


Reply With Quote
  #3  
Old   
Lew
 
Posts: n/a

Default Re: If criteria is Null then show all. - 03-09-2007 , 09:26 AM



Lew wrote:
Quote:
valntyn via DBMonster.com wrote:
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


Reply With Quote
  #4  
Old   
HansH
 
Posts: n/a

Default Re: If criteria is Null then show all. - 03-09-2007 , 11:23 AM



"valntyn via DBMonster.com" <u29706@uwe> schreef in bericht
news:6ed7203954842 (AT) uwe (DOT) ..
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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.