sp_executesql MAXDOP

  • Just trying to test the affect of MAXDOP = 1 inside a query executed by sp_executesql within CRM. The query itself has lots of variables, so takes a similar form to the below, (excuse the copying and pasting):

    exec sp_executesql N'select top 51 when 6 then @StatusCode1 when 1 then @StatusCode2 ORDER BY incident0.TicketNumber desc

    @StatusCode1=N'Canceled',@StatusCode2=N'In Progress'

    My question really is this, where to put the OPTION MAXDOP(1) command, I put it right at the end but its seemingly ignored?

    Many thanks!

    'Only he who wanders finds new paths'

  • ...

    exec sp_executesql N'select top 51 when 6 then @StatusCode1 when 1 then @StatusCode2 ORDER BY incident0.TicketNumber desc

    @StatusCode1=N'Canceled',@StatusCode2=N'In Progress'

    SQL you have posted will not compile as it's invalid - there is no FROM table mentioned and there is no closing quote at the end of sel string.

    MAXDOP should be specified at the end of query you are executing as OPTION (MAXDOP 1)

    So, your call should look like:

    exec sp_executesql

    N'select top 51 when 6 then @StatusCode1 when 1 then @StatusCode2

    FROM incident0

    ORDER BY incident0.TicketNumber desc OPTION (MAXDOP 1);',

    @StatusCode1=N'Canceled',@StatusCode2=N'In Progress'

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Apologies for the rather hasty copy and paste snippets that weren't exactly workable and thank you for the reply. The query is rather mammoth in size and I was having difficulty cutting out the sensitive information parts so thought I would take a punt!

    However, the example you provided was spot on, thank you very much! 🙂

    'Only he who wanders finds new paths'

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply