troubleshooting Question

Conditional Left Join

Avatar of GENTP
GENTP asked on
DatabasesMicrosoft SQL ServerSQL
3 Comments2 Solutions923 ViewsLast Modified:
Is there a way to conditionally do a left join?

Basic layout of the problem is that I'm joining to a contacts table. I want to grab contact type X, but if it doesn't exist, then I want to grab contact type Y.


      LEFT JOIN [tbl_sb_contactsToProjects] [cont]
      ON [proj].[ID] = [cont].[projectID] AND ([cont].[roleid] = 11)
If this is null, then I want to pull from ([cont].[roleid] = 10)

Please keep in mind that this is in the middle of a query that is joining 5 or 6 tables already, so it won't be easy to completely change things.

Thanks for the help!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros