I have a list of column names, for example ('Name', 'Code', 'Title') that can be array but not necessarily, it can be anything. I just have a list of column names.
Then I have to create a dynamic SQL select that has to be executed later. That dynamic SQL select is generating XML, so it uses for xml path, here is a simplified version:
@sql = select @column_name, some_fixed_column
from t_table
where some_Condition
for xml path;
this has to be dynamic query plus it creates XML, but I want to make it somehow go through all column names from the list, so the general outcome would be something like:
select Name, some_fixed_column from tb_table where some_Condition for xml path;
select Code, some_fixed_column from tb_table where some_Condition for xml path;
select Title, some_fixed_column from tb_table where some_Condition for xml path;
I can't even use + or Union because it doesn't work with for xml path queries (I tried). The query is quite complicated and it already works on multiple XML levels.
Is this even possible?