Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Join statement
Message
 
 
To
16/03/2010 12:41:44
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01454733
Message ID:
01454842
Views:
39
This message has been marked as the solution to the initial question of the thread.
>Hi
>
>How would I modify this SQL statement so that if a MessageID exists in both tables, the resulting table should ONLY take the record from the ApplicationMessage table?
>
>select * from dbo.SystemMessage where MessageID = @LnMessageID
> union all
>select * from dbo.ApplicationMessage where MessageID = @lnMessageID
>order by MessageID
>
>Regards

The simplest way would be
select * from dbo.SystemMessage where MessageID = @LnMessageID
and not exists (select 1 from dbo.ApplicationMessage where MessageID = @lnMessageID)
   union all 
select * from dbo.ApplicationMessage where MessageID = @lnMessageID
order by MessageID
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform