I would like to create a stored procedure with parameters that indicate which fields should be selected.
E.g. I would like to pass two parameters “selectField1” and “selectField2” each as bools.
Then I want something like
SELECT
if (selectField1 = true) Field1 ELSE do not select Field1
if (selectField2 = true) Field2 ELSE do not select Field2
FROM Table
Thanks
Karl
Sounds like they want the ability to return only allowed fields, which means the number of fields returned also has to be dynamic. This will work with 2 variables. Anything more than that will be getting confusing.
Dynamic SQL will help with multiples. This examples is assuming atleast 1 column is true.