Results 1 to 3 of 3

Thread: 3M records query timeout

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Location
    Accra, Ghana
    Posts
    26

    3M records query timeout

    I have an SQl Server 7.0 table with 3 million records this table is indexed on the ff. fields Terminal_Nb and Draw_Nb.

    I need to run this query but always get timed out. Can you please help. How best to optimize the query. Thanks


    Select distinct Terminal_No, Draw_nb,

    (Select sum(Gross_Sales) from tickets where terminal_no = qrysales.Terminal_No and Draw_No = qrySales.Draw_Nb as Gross),

    (Select sum(Gross_Sales) from tickets where terminal_no = qrysales.Terminal_No and Draw_No = qrySales.Draw_Nb and cancel_Date is not null as Cancels),


    (Select sum(VAT) from tickets where terminal_no = qrysales.Terminal_No and Draw_No = qrySales.Draw_Nb as VATreturns),

    (Select sum(Gross_Sales - VAT) from tickets where terminal_no = qrysales.Terminal_No and Draw_No = qrySales.Draw_Nb as ActualStake),

    (Select sum(To_Pay) from tickets where terminal_no = qrysales.Terminal_No and Draw_No = qrySales.Draw_Nb and Payment_Date is not null as Payment)

    from tickets qrySales

  2. #2
    Swatty
    Guest
    Can't you make some views on the server.

    Then later do a select on them.

  3. #3
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Paste the query into query analyzer then use the Index Tuning Wizard on the query menu.

    This will tell you if there are nay indexes needed.
    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width