I’m looking for an elegant way to select fields from a view, where a second supporting table defines the fields that should be selected.
The view contains all of my employee data. The constraint table contains the field name, which references the view field name, and a bit which signifies to select that field.
Example of View:
Name | Age | Weight
Peter | 38 | 180
Martha | 25 | 115
Example of constraint table:
Field | Enabled
Name | 1
Age | 0
Weight | 1
…Where after running the query, the following data should return:
Name | Weight
Peter | 180
Martha | 115
Any ideas on how to approach this?
Thanks!
will execute
Bring on the dynamic sql haters.
Using this like a table or view is not trivial but it is possible, first wrap it in a stored procedure, then create a linked server ‘loopback’
Then you can use the following syntax: