Using TOP in the Select is slow

  • Running the below SQL statements is slow

    declare @P1 int

    set @P1=0

    declare @P2 int

    set @P2=16388

    declare @P3 int

    set @P3=8193

    declare @P4 int

    set @P4=0

    exec sp_cursoropen @P1 output, N'SELECT TOP 1 "State:" FROM "EXTERNAL_SUPPORT"."Incident"  WHERE "Incident #" = 1884', @P2 output, @P3 output, @P4 output

    select @P1, @P2, @P3, @P4

    when I use Select TOP 1 * instead of Select TOP 1 "State:" is also slow.

    When I use Select * by removing TOP 1, the query returns in a sec.

    Can anyone shed some light on this?

     

  • try putting an order by clause in

    www.sql-library.com[/url]

  • Try not using a cursor ...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 3 posts - 1 through 2 (of 2 total)

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