INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Using the IF function in a WHERE clause

Using the IF function in a WHERE clause

(OP)
Hi,

I need to build a query with a WHERE clause for a Crystal report that essentially tests for something and if true, builds the rest of the WHERE clause one way, and if false, builds the rest another way. I would like to be able to do something like this:

WHERE LeaseCompany.LeaseCompanyNum = '09' AND LeaseDatabase.LeaseTerminationDate = 0 AND
OpeninvAutoSchedule.AutoSchSeqNum = 1 AND LeaseEquipment.EquipSaleInvDate = 0 AND
IF(LeaseDatabase.LeaseMaturityDate > 20041104, OpeninvAutoSchedule.AutoschNum = 1,
OpeninvAutoSchedule.AutoScheduleStartDate1 >= LeaseDatabase.LeaseMaturityDate AND OpeninvAutoSchedule.AutoschNum > 1)

However when I try to run this I get an ODBC Error (right after the first OpeninvAutoSchedule.AutoschNum it chokes). Is it possible to do what I'm trying to do another way?

Thanks very much for any help or suggestions.


Robin

RE: Using the IF function in a WHERE clause

The IF function has the following format:
IF(<expression>,<True Value>, <False Value>)
Your IF doesn't seem to follow that structure.

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
Custom VB and Btrieve development.
http://www.mirtheil.com

RE: Using the IF function in a WHERE clause

(OP)
I thought it did -- it has each of the three parts, separated by commas, enclosed by parentheses.  Can you tell me how my syntax is incorrect?  Thank you!

RE: Using the IF function in a WHERE clause

Well, looking at it, it does seem to have the three parts separated by commas:
IF(LeaseDatabase.LeaseMaturityDate > 20041104, OpeninvAutoSchedule.AutoschNum = 1,
OpeninvAutoSchedule.AutoScheduleStartDate1 >= LeaseDatabase.LeaseMaturityDate AND OpeninvAutoSchedule.AutoschNum > 1)
But, "OpeninvAutoSchedule.AutoScheduleStartDate1 >= LeaseDatabase.LeaseMaturityDate AND OpeninvAutoSchedule.AutoschNum > 1" is an expression, not a value.  The same is true of "OpeninvAutoSchedule.AutoschNum = 1".  They are both expressions.  What happens if you change it, for the sake of testing, to:
IF(LeaseDatabase.LeaseMaturityDate > 20041104,1,2)

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
Custom VB and Btrieve development.
http://www.mirtheil.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close