Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Option to or not to use JOIN
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00883735
Message ID:
00884627
Views:
10
Hi John,

An untested idea, may not even work.
SELECT * FROM tableA
    LEFT JOIN tableB ON tableA.ID=@tableB.ID
    LEFT JOIN tableC ON tableA.ID2=@tableC.ID
    LEFT JOIN tableD ON tableA.ID3=@tableD.ID
WHERE 
	( @tableB.ID IS NOT NULL OR NOT EXISTS (SELECT * FROM tableB)
			AND
	( @tableC.ID IS NOT NULL OR NOT EXISTS (SELECT * FROM tableC)
			AND
	( @tableD.ID IS NOT NULL OR NOT EXISTS (SELECT * FROM tableD)
>Thanks for your reply as always Sergey. However, I must of not been very clear in my problem.
>
>I know about using the OUTER JOIN but in this particular case I either only want to pull all "or" pull only those that match depending upon if lookup table contains any records to do a JOIN. Using OUTER JOIN will "always" pull all from one table and this is not what I want.
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform