Reduce the store Procedure execution time

  • SS999 (3/27/2012)


    Currently its on sql server 2005.

    You posted in a SQL Server 2008 forum, that usually means you will get SQL Server 2008 answers that don't necessarily work in SQL Server 2005.

    We make assumptions based on where a post is made.

  • I will make sure to post in a right way next time. Apologies!!!

  • SS999 (3/27/2012)


    I will make sure to post in a right way next time. Apologies!!!

    None needed. Now that we know we are dealing with SQL Server 2005, we just make some adjustments to what we suggest.

  • When i run the original sp i m getting 616rows, but whem i m running the sp given by elutin, i m getting only 242 rows.

  • You had missing brackets (and wildcard %) in your WHERE clause - in place where you check for FirstName or LastName:

    ...

    WHERE dpr.AgentID = @TempVQAgentID AND dpr.StateID = @TempVQStateID

    AND (((@TempVQAppFName <> '' AND @TempVQAppFName IS NOT NULL AND @TempVQAppLName <> '' AND @TempVQAppLName IS NOT NULL)

    AND dpr.InsuredName1 LIKE '%' + @TempVQAppFName + ' ' + @TempVQAppLName + '%' OR dpr.InsuredName2 LIKE '%' + @TempVQAppFName + ' ' + @TempVQAppLName)

    ...

    Hard to see where? It's extremely helpful to format and indent T-SQL code...

    Your current condition would select everything where

    "InsuredName2 LIKE '%' + @TempVQAppFName + ' ' + @TempVQAppLName", It should be in brackets together with check of dpr.InsuredName1...

    As you can guess, I cannot run and check the code I've written. As I don't have your database.

    _____________________________________________
    "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]

Viewing 5 posts - 31 through 34 (of 34 total)

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