lundi 1 novembre 2021

Can I use OPTION (MAXDOP 1) for a query within an IF statement in SQL SERVER

I want to preface this with the fact that I do understand that using OPTION (MAXDOP) is generally frowned upon and undesirable. However, just saying "don't use OPTION (MAXDOP)" does not address the narrow focus of the question at hand. For purposes of this question, say I have a scenario where I am backed into a corner, and this is something I'm stuck with due to other issues that are beyond what I actually want to ask for this specific question. Let's not get stuck on those reasons for the time being please. Specifically for this question, I am writing a stored procedure wherein I have an IF statement something like:

IF ((SELECT TOP 1 Identifier FROM SomeTable WHERE ) IS NOT NULL) BEGIN END

I would like the query within the IF statement to run with OPTION (MAXDOP 1) - again, I know this is generally not what you'd want to do, let's save that discussion for the sake of this question. Can I do this? It seems like whether I put the OPTION (MAXDOP 1) bit at the end of the line with the IF, immediately after IS NOT NULL, or after , my query editor is telling me it's not allowed there. Is there somewhere I can put it to make this occur?

Aucun commentaire:

Enregistrer un commentaire