Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Join statement
Message
 
 
À
16/03/2010 08:27:08
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01454733
Message ID:
01454738
Vues:
49
>Hi
>
>I'm performing the following stored procedure to essentially join 2 tables, with identical structures, to amalgamate the list of system/application messages into one dataset:
>
>as
>begin
>set nocount on;
>select * from dbo.SystemMessage union all select * from dbo.ApplicationMessage order by MessageID
>end
>
>I now want to pass a parameter into this stored procedure, @lnMessageID, and I'd like the statement to perform the join and THEN return the record from the joined results that matches @lnMessageID. @lnMessageID is always unique.
>
>Regards

In my opinion, it would be easier to add WHERE condition to both parts instead, e.g.
select * from dbo.SystemMessage where MessageID = @LnMessageID
   union all 
select * from dbo.ApplicationMessage where MessageID = @lnMessageID
order by MessageID 
Alternatively, you can go with the derived table, but I don't see a benefit.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform