Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 "SQL queries time out expired"

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-12-22 : 08:30:24
Parimal writes "I have a table with 650000+ rows having detailed rows, header table contains 55000+ row, when I try to execute a query wherein i want to get the sum(some_value_field) group by certail fields and using INNER JOINS of almost 5 tables, it gives me a "TimeOut expired" error

Hope, you must already have the solution to the above.
Given below is the query used:

select b.sp, a.cocode, d.coname, a.cd, sum(a.itval) from
adtsbl a INNER JOIN adtmbl b on a.billno = b.billno
INNER JOIN admtco d ON a.cocode = d.cocode
where b.billdt between convert(datetime,'01/04/2003',103) and
convert(datetime,'30/11/2003',103)
group by a.sp, a.cocode, d.coname, a.cd
order by a.sp, a.cocode, d.coname, a.cd"

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-12-22 : 08:53:12
My guess is your CONVERTs are taking up too much time - casts across datatypes are always expensive. You can use the yyyymmdd format for dates, they are always unambiguous. Try this:

WHERE b.billdt BETWEEN 20030401 AND 20031103


Owais

We make a living out of what we get, but we make a life out of what we give.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-12-22 : 12:01:40
actually, that shouldn't be a problem. the convert is done once, not for each row, so it should be OK.

Do you have an index on the billdt column? My guess is that you don't. How about all the other columns you are joining on? (i.e., billno and cocode)? Make sure all of those columns are indexed and you should have no trouble with 650,000 rows ...

- Jeff
Go to Top of Page
   

- Advertisement -