Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Condition select with Union
Message
 
 
To
28/04/2014 10:27:31
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01599171
Message ID:
01599172
Views:
86
This message has been marked as the solution to the initial question of the thread.
>I have a select which is conditional. So, basically, if it would only be that one, I would put that into a IF and only execute that SQL if the condition matches. However, when the condition matches, I need to include that with a Union. So, what is the best way to achieve that. Here is an example:
>
>
>SELECT Client.Title FROM Client WHERE Client.NoProvince=22
> UNION
>SELECT Client.Title FROM Client WHERE Client.NoProvince=23
>
>
>So, basically, in some circumstances, the first select should not be considered.
>
>Or, is simply putting that select into the first part of the IF and the smaller select in the Else would do?

You can add condition to the first part of the UNION that will evaluate to false in these circumstances, e.g

select Client.Title from Client WHERE Client.NoProvince = 22 AND False Condition
UNION
...
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