I would like to call a stored procedure with an integer variable @Mdop
so that the query in the stored procedure reads something like:
SELECT someField
FROM SomeTable
OPTION (MAXDOP @Mdop)
Is there a way to do this? The only trivial way I found is having a giant IF THEN ELSE
and, for each Maxdop
value I plan to pass to the stored procedure, repeat the same query with different maxdop
values. I find this approach original but quite horrifying.
Other ideas?
Build your query dynamically and then execute it.