Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sp_executesql MAXDOP Expand / Collapse
Author
Message
Posted Thursday, August 1, 2013 3:53 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:02 AM
Points: 211, Visits: 842
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'
Post #1479847
Posted Thursday, August 1, 2013 4:01 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
...
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1479851
Posted Thursday, August 1, 2013 4:19 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 3:02 AM
Points: 211, Visits: 842
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'
Post #1479861
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse