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

"...I have found your site brilliant. What makes it good are the people that contribute to the site..."

Geography

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

IF statement in where clause

acesn8s (Programmer)
22 May 08 10:39
Hi, I am trying to SELECT records from 2 tables. I want to get records WHERE TABLE2_TERM_DATE is NULL unless the TABLE2_CONTACT field is NOT NULL. If the TABLE2_CONTACT is NULL and TABLE2_TERM_DATE is Null then I don't want those records. Below is the code I have so far, any help would be appreciated.

SELECT *                       
FROM TABLE1, TABEL2   
WHERE TABLE1_ID = TABLE2_ID   
AND TABLE2_TERM_DATE is NULL and TABLE1_CHANGE_IND is NULL
AND TABLE1_ACTIVITY_DATE >= '01-MAY-05'
ORDER BY TABLE1_LAST_NAME, TABLE1_FIRST_NAME, TABLE1_MI, TABLE1_ID
Golom (Programmer)
22 May 08 12:05

CODE

SELECT *

FROM TABLE1, TABLE2

WHERE TABLE1.ID = TABLE2.ID
  AND TABLE1.CHANGE_IND IS NULL
  AND TABLE1.ACTIVITY_DATE >= '01-MAY-05'

  AND TABLE2.TERM_DATE IS NULL

  AND NOT (TABLE2.CONTACT IS NULL AND TABLE2.TERM_DATE IS NULL)

ORDER BY TABLE1.LAST_NAME, TABLE1.FIRST_NAME, TABLE1.MI, TABLE1.ID
acesn8s (Programmer)
22 May 08 13:07
Thank you very much Golom. I was tring Case statements and that wasn't working out for me and I did not know that I could wright a statement like:
AND NOT (TABLE2.CONTACT IS NULL AND TABLE2.TERM_DATE IS NULL)

 
Golom (Programmer)
22 May 08 15:52
You can't wright* one ... but you can write one.


* Definition - a worker skilled in the manufacture especially of wooden objects  
acesn8s (Programmer)
23 May 08 8:07
LOL! Thank you for that correction as well.

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!

Back To Forum

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