You can't generate a dynamic pivot without using dynamic SQL. Which means you have to use
EXEC
.
You could potentially use
sp_executesql[
^] if you had parameters to pass in. But you can't pass the pivot column names as parameters.
The only other option would be for your query to return the raw data, and for your application to perform the pivot in code.