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!
  • Students Click Here

*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.

Students Click Here


Join, And, and Or problem

Join, And, and Or problem

Join, And, and Or problem


I am having a problem involving the following query:


Qn.QuestionId AS QnQuestionID,
Qn2.QuestionId AS Qn2QuestionID,
QuestionID = CASE WHEN Qn.QuestionID IS NULL THEN Qn2.QuestionID ELSE Qn.QuestionID END

          t_cp_Agency       Ag
JOIN      t_cp_Answer       An  ON An.AgencyId = Ag.AgencyId  
LEFT JOIN t_cp_Question     Qn  ON Qn.QuestionId = An.QuestionId
LEFT JOIN t_cp_QuestionItem QI  ON QI.QuestionItemId = An.QuestionItemId  
LEFT JOIN t_cp_Question     Qn2 ON Qn2.QuestionID = QI.QuestionID  

The query runs fine (returns 57 rows) until I try to show all records except the one for a particular question id. But, because of the joins, I have to test for two question ids: Qn.questionID and Qn2.QuestionID. I would have thought that the following would work:


WHERE Qn.QuestionID <> 166 AND Qn2.QuestionID <> 166

but it doesn't! If I use that, the query returns no rows. If I change the AND to an OR it works. Can anyone please help me understand why?

Thank you!

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!

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