Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
One of 3 possible joins...
Message
De
05/08/2004 13:06:15
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00930847
Message ID:
00931086
Vues:
21
This message has been marked as the solution to the initial question of the thread.

I want to do a join between two tables - but there are three possible ways I can join them.


I know I can do three JOIN ... AS ... statements and just have a seperate result field for each option (which I can subsequently check in code with nested Visual FoxPro IIF's), but I was hoping for a prettier way involving fewer fields in the returned cursor.

Any suggestions from the experts out there?


COALESCE() function:
SELECT * FROM table1 join table2 
on table2.primarykey=
COALESCE(
-- If the Foreign Key exists, I want to join on that
table1.foreignKey  
- but if it doesn't, I'll create a join on another field (through an intermediate table)
,(SELECT * FROM intermediateTable where ???=anotherfield)
and if there's no corresponding record in the intermediate table, I'll try a join on another field before finally giving up and returning a NULL.
,(try with another table)
)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform