Jump to content

conditional add clause


jimfog
 Share

Recommended Posts

take a look at this query...it has a series of AND clasues..pay attention to the 3rd commented..it sums up what I want to do.

SELECT lastname,city FROM users
INNER JOIN business_users
 ON business_users.user_ID=users.user_ID 
WHERE   users.active=1  
AND business_users.sched_entered =1 
AND business_users.services_entered=1
--and  business.users.staff_entered=1 only if business.users.sraff_enfaged_in_appt=1
 AND lastname LIKE  'p%';

I want to ask as prerequisite business.users.staff_entered ONLY if business.users.sraff_enfaged_in_appt column is true.

How I would go about achieving that?

Link to comment
Share on other sites

You just need to break that down into its logical components.

If you only want to test that field X is 1 when field Y is 1, it's like always returning true when field Y is 0 and only sometimes returning true when field Y is 1.

The result would look like this:

AND (
  Y = 0 /* Value of field X does not matter when Y is 0 */
  OR
  Y = 1 AND X = 1 /* Value of field X matters when Y is 1 */
)

 

Link to comment
Share on other sites

that did,,,not used to in applying the rules of logic in sql...probably you might say that they no differ from other languages and you would be right....anyway..tnanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...