Other that duplicating a query in an sproc, is there any way to specify a hint based on an sproc parameter? For example, with parameter @waitForLock, if it’s set to 0 I want to use the READPAST hint, otherwise wait/block until the other transaction completes.
Other that duplicating a query in an sproc, is there any way to specify
Share
In general I like the
OPTION RECOMPILEsuggestion, though that means it will recompile every time, even if stats or your parameter haven’t changed. This is usually to thwart parameter sniffing, not help with cases where you want to avoid or not avoid taking locks.One idea is to use dynamic SQL (which can also be beneficial depending on your “optimize for ad hoc workloads” setting and the frequency you run with one parameter or the other).