Created
September 3, 2013 10:05
-
-
Save DaveHogan/6421973 to your computer and use it in GitHub Desktop.
How to select from different tables in a VIEW based on a config value / IF condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Sneaky way to select from a specific table using a config value | |
| -- Views do not support IF or anything else useful | |
| -- Obviously the table schemas need to match otherwise the UNION will fail | |
| SELECT t.* FROM ATable t | |
| INNER JOIN Config c on 'ConfigKeyToMatch' = c.ConfigKey | |
| WHERE c.ConfigValue = 'True' | |
| UNION | |
| SELECT t.* FROM DifferentTable t | |
| INNER JOIN Config c on 'ConfigKeyToMatch' = c.ConfigKey | |
| WHERE c.ConfigValue = 'False' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment