Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIf in Inner Join?

Status
Not open for further replies.

ormsk

Programmer
Sep 30, 2002
147
GB
I am not sure if this is possible...

I want to create a query that will dynamically refer to an INNER JOIN statement dependant on a value of a field

e.g
Code:
SELECT Documents.ID , Documents.Type
FROM Documents INNER JOIN Owners ON Documents.UserID = Owners.ID;

The above is straightforward enough, but the [red] Documents.Type [/red] has values where there is no lookup table. For example, if [red] Documents.Type =9 [/red], then I want the dat returned to be as though the SQL statement is ...
Code:
SELECT Documents.ID , Documents.Type
FROM Documents INNER JOIN DifferentTable ON Documents.UserID = DifferentTable.ID;

I am not the gatekeeper of the database, so I am unable to add or modify tables, but I want to be able to get aroung this problem.


**********************************
There is more than one way to skin a cat...but who wants a skinned cat?
 
Would a union suit?

Code:
SELECT Documents.ID , Documents.Type
FROM Documents INNER JOIN Owners ON Documents.UserID = Owners.ID 
WHERE Documents.Type<>9
UNION
SELECT Documents.ID , Documents.Type
FROM Documents INNER JOIN DifferentTable ON Documents.UserID = DifferentTable.ID
WHERE Documents.Type=9

Depending on your set-up, a union of Owners and Different table may also suit.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top