How To Filter The Result Of An Execute(@query) By Where Clause?
I'd like to know how to filter (put where clause) in the result of a dynamic query like this: execute(@query) The problem is the number of columns of @query is dynamic and titles
Solution 1:
set @query = N'select * from (' + @query + N') t where [col1] = ''something''';
exec (@query)
You could use the unpivoted table to figure out what the name of the column would be, and use this in place of col1.
Post a Comment for "How To Filter The Result Of An Execute(@query) By Where Clause?"