SELECT * FROM Customer Ledger Entry WITH(READUNCOMMITTED) WHERE "Posting Date" >= @P1 AND "Customer No" = @P2 ORDER BY "No" OPTION (OPTIMIZE FOR UNKNOWN) SELECT * FROM Customer Ledger Entry WITH(READUNCOMMITTED) WHERE "Posting Date" >= @P1 AND "Customer No" = @P2 AND "No" > @P3 ORDER BY "No" OPTION (OPTIMIZE FOR UNKNOWN)
use [NavisionDB] exec sp_create_plan_guide @name = N'CustLedgerEntry_Guide1', @stmt = N' SELECT * FROM Customer Ledger Entry WITH(READUNCOMMITTED) WHERE "Posting Date" >= @P1 AND "Customer No" = @P2 AND "No" > @P3 ORDER BY "No" OPTION (OPTIMIZE FOR UNKNOWN)', @type = N'SQL', @module_or_batch = NULL, @params = N'@P1 datetime,@P2 varchar(20),@P3 varchar(20)', @hints = N'OPTION (TABLE HINT("Customer Ledger Entry", INDEX(NCI_1), READUNCOMMITTED))'
Comments
anyone? Do you need further information?
Best regards
Elessar
Dont know if you have found any solution,
Normally you should check it using SQL profiler with ShowPlan XML Event to see th eexecution plan.
You should Keep your SQL Server to latest available build.
But may be you can try using the "FORCESEEK" Parameter in the N'OPTION (TABLE HINT("... plan guide, if this helps?
Arvind
So I think that forceseek also doesn't work, because it also creates a cached plan.
I think it will work if you use the recompile hint, because the plan will not be cached in that situation, so it's save for the optimizer to sniff parameters and create a plan for the actual parameter values. Iirc you need to have SQL Server 2008 R2 SP1 or later.
regards
ndbcs