SQL Statements

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

Is there any difference between these 2 SQL statements?
The where clause...

1
SELECT PayName.PaymentNameID, PayName.PaymentName,
PayName.ExpirationDate, SecurityDetails.SecurityID,
SecurityDetails.Active, Privleges.PrivID, Privleges.PayTag
FROM (SecurityDetails INNER JOIN Privleges ON SecurityDetails.PrivID =
Privleges.PrivID) INNER JOIN PayName ON Privleges.PayTag =
PayName.PaymentType
WHERE (((PayName.PaymentName) Not Like "Coupon") AND
((PayName.ExpirationDate) Is Null) AND ((SecurityDetails.Active)=-1)) OR
(((PayName.ExpirationDate)>Now()))
ORDER BY PayName.PaymentName;

2
SELECT PayName.PaymentNameID, PayName.PaymentName,
PayName.ExpirationDate, SecurityDetails.SecurityID,
SecurityDetails.Active, Privleges.PrivID, Privleges.PayTag
FROM (SecurityDetails INNER JOIN Privleges ON SecurityDetails.PrivID =
Privleges.PrivID) INNER JOIN PayName ON Privleges.PayTag =
PayName.PaymentType
WHERE (((PayName.PaymentName) Not Like "Coupon") AND
((PayName.ExpirationDate) Is Null) AND ((SecurityDetails.Active)=-1)) OR
(((PayName.PaymentName) Not Like "Coupon") AND
((PayName.ExpirationDate)>Now()) AND ((SecurityDetails.Active)=-1))
ORDER BY PayName.PaymentName;

Will they work the same?

Thanks
DS
 
Paste the two WHERE statements into Notepad and reformat them,
eliminating superfluous parentheses and using indents to make it clearer
what belongs with what. You'll end up with something like this:

1
WHERE (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate Is Null)
AND (SecurityDetails.Active=-1)
) OR (
PayName.ExpirationDate)>Now()
)

2
WHERE (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate Is Null)
AND (SecurityDetails.Active=-1)
) OR (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate>Now())
AND
(SecurityDetails.Active=-1)
)

which makes the difference clear: 1 includes ALL records where
ExpirationDate is in the future, while 2 restricts them by PaymentName
and Active as well.
 
John said:
Paste the two WHERE statements into Notepad and reformat them,
eliminating superfluous parentheses and using indents to make it clearer
what belongs with what. You'll end up with something like this:

1
WHERE (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate Is Null)
AND (SecurityDetails.Active=-1)
) OR (
PayName.ExpirationDate)>Now()
)

2
WHERE (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate Is Null)
AND (SecurityDetails.Active=-1)
) OR (
(PayName.PaymentName Not Like "Coupon")
AND
(PayName.ExpirationDate>Now())
AND
(SecurityDetails.Active=-1)
)

which makes the difference clear: 1 includes ALL records where
ExpirationDate is in the future, while 2 restricts them by PaymentName
and Active as well.
Thanks, that clears a lot of questions up for me! I appreciate the input!
Thanks
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Not Like 4
Complex If Statement 6
Find as you type question 0
Access Instead of 31 rows for March, the view shows 62 records.... 0
SQL Quotes 7
SubQuery Problem 7
Multi fields search form 1
SQL Syntax for multiple table joins 7

Back
Top