Hi,
I am on SQL Server 2008.
We have a web front end, which gives calls to a third party software (black box), which call stored procedures in our database. These procedures are given by the 3rd party, hence we are not allowed to change them. One of the procedures receive input parameter string and it calls something like,
"SELECT ID FROM EMPLOYEE AS em, ATTRIBUTES AS att WHERE em.NAME LIKE @input_parameter .... {followed by very complex query and sub query}".
If I run this query on its own (not from stored proc), replacing input parameter with JONES% (wildcard in the end), the query runs very fast and shows a nice/efficiant plan. If I run the query with %JONES%, it takes much longer and the join order (and complete query execution path) is very different. I don't think there is anything hugely wrong in it as standalone SQL.
The real problem is, 95% of the calls to the stored procedure has input parameter like JONES% (wildcard not in the begining), but the query plan which sql server runs is assuming it is %JONES%. Basically, sql server always creates/uses the worst case plan for the stored proc execution.
Question is, is it possible that SQL server creates multiple plans (one for JONES%, another for %JONES%) and use the appropriate plan depending on the value of @input_parameter???? Is it possible without changing the stored proc? is there any such setting at server/database/table level?
Thanks in advance