|
-
Jul 2nd, 2002, 05:05 AM
#1
Thread Starter
Junior Member
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
-
Jul 2nd, 2002, 06:21 AM
#2
Can't you make some views on the server.
Then later do a select on them.
-
Jul 2nd, 2002, 06:33 AM
#3
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|