If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > WHERE x = x except if x = NULL then show all records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-08, 02:38
Chevron22 Chevron22 is offline
Registered User
 
Join Date: Apr 2008
Posts: 5
Talking WHERE x = x except if x = NULL then show all records

Hi guys, hope someone can help... I am pulling records from a simple access DB where account number of login = account number of payments table then show record. However i am trying to achieve if the account number = "NULL ENTRY" then show all records in the Payments table

here is my code so far

"SELECT * FROM Payments WHERE Payments.AccNumber = " & AccNum & " ORDER BY DateEntered"

Thanks is advance

Last edited by Chevron22; 04-17-08 at 07:00.
Reply With Quote
  #2 (permalink)  
Old 04-17-08, 11:50
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
SELECT *
FROM   accounts
WHERE (acctNum = @param
 OR    @param IS NULL)
??
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 04-22-08, 15:17
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
WHERE nz(@param, acctNum) = acctNum
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #4 (permalink)  
Old 04-23-08, 00:50
Chevron22 Chevron22 is offline
Registered User
 
Join Date: Apr 2008
Posts: 5
Wink

Quote:
Originally Posted by Teddy
WHERE nz(@param, acctNum) = acctNum
What does the nz stand for here?

cheers
Reply With Quote
  #5 (permalink)  
Old 04-23-08, 07:22
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
NZ = Non-Zero

It converts NULLs into a specified value; in this case, if @param is null the expression essentially becomes
Code:
WHERE acctNum = acctNum
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On