Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Congratulations for your great site. This site helped me more than university..."

Geography

Where in the world do Tek-Tips members come from?

Using the IF function in a WHERE clause

duncanstreet2004 (MIS)
4 Nov 04 19:05
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
mirtheil (Programmer)
4 Nov 04 19:57
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

duncanstreet2004 (MIS)
5 Nov 04 10:23
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!
mirtheil (Programmer)
5 Nov 04 17:34
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

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!

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