locked
strange problem in my query !!! RRS feed

  • Question

  • hi all ,

    how are u???

    i have strange problem in my query , when i write this query there is no problem , its run fast:

    select blabla from blablaa where blala.blala=10                                    <===== it will run fast

    in the seconde below query, the query may slowly:

    DECLARE @VAR1 int

    set @VAR1 =10

    select blabla from blablaa where blala.blala=@VAR1                                          <===== it will run slowly

    Wednesday, March 28, 2012 11:10 AM

Answers

  • Have a look at the following forum thread:

    query performance issue

    - Krishnakumar S

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:16 AM
  • You not executing this as part of an SP are you..

    Check when was the last statistics update occurred on  the table..

    Please execute 

    UPDATE STATISTICS yourtable with FULLSCAN 

    vt


    Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:17 AM
  • 1) 

    DECLARE @VAR1 int

    set @VAR1 =10

    select blabla from blablaa where blala.blala=@VAR1       OPTION(RECOMPILE)???

    2) 

    EXEC sp_executesql N'SELECT  blabla 
    FROM  from blablaa 
    WHERE  blala.blala = @VAR1', N'@VAR1 INT', 10

    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:39 AM
    Answerer

All replies

  • Have a look at the following forum thread:

    query performance issue

    - Krishnakumar S

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:16 AM
  • You not executing this as part of an SP are you..

    Check when was the last statistics update occurred on  the table..

    Please execute 

    UPDATE STATISTICS yourtable with FULLSCAN 

    vt


    Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:17 AM
  • 1) 

    DECLARE @VAR1 int

    set @VAR1 =10

    select blabla from blablaa where blala.blala=@VAR1       OPTION(RECOMPILE)???

    2) 

    EXEC sp_executesql N'SELECT  blabla 
    FROM  from blablaa 
    WHERE  blala.blala = @VAR1', N'@VAR1 INT', 10

    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

    • Marked as answer by greaso Saturday, March 31, 2012 7:27 PM
    Wednesday, March 28, 2012 11:39 AM
    Answerer