Any ideas to change this query to make it run faster?

  • These 2 examples both work, but they take a very long time and sometimes lock up. Any ideas to speed them up?

    Attach Code

    Example 1:

    selectDISTINCT code

    fromData

    WHERE codeIS NOT NULL

    --This query runs within the above code's looping output

    selecttop 5 items as test

    fromData

    WHERE code= '#code#'

    loop

    #test#

    end loop

    Example 2:

    SELECTr1.repfacility,

    r1.itemsid AS test

    FROMReportdata r1

    WHEREr1.itemsid IN

    (SELECT TOP 5 r2.itemsid

    FROMReportdata r2

    WHEREr2.repfacility = r1.repfacility)

    ORDER BY r1.repfacility, r1.itemsid

    #repfacility#

    #test#

  • What exactly does "This query runs within the above code's looping output" mean?  Does this mean that you've written a cursor?  Please post all of your code, DDL for relevant tables, some sample data, and info pertaining to table row counts/table size and indexing info.  Also, when you say that they take a very long time, how long is that to you?  What happens when it 'locks up'?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

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

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