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
 General SQL Server Forums
 New to SQL Server Programming
 Index Help

Author  Topic 

sanjnep
Posting Yak Master

191 Posts

Posted - 2007-10-28 : 16:06:40
I have following query to calculate running total and it has about half million rows. On which column can I put correct index to get fast result? I put clustered index on OrderID column and it is taking 25 mins to run. I am using SQL Server 2005.
Thanks

____________________________________________________________________
select OrderId,sfID,pbnID,ctcID,mmID, OrderDate, O.OrderAmt
,(select sum(OrderAmt) from Orders
where OrderID <= O.OrderID
and sfID = O.sfID and pbnID = O.pbnID and mmID = O.mmID
)
'Running Total'
from Orders O

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-10-28 : 18:20:20
I'd do it in the front end, at least until SQL Server's OVER() function catches up to Oracle!
Calculating a running total does not even make sense without an ORDER BY.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-28 : 18:32:26
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6027

good information there on the topic
Go to Top of Page
   

- Advertisement -