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 2008 Forums
 Transact-SQL (2008)
 over()

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2012-10-23 : 04:55:31
why it didnt recognize order?

select EventDate ,ProductCd,CustomerNo ,sum(Quantity) OVER (ORDER BY EventDate ) AS RunningTotal
from #TableR

error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'order'.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-10-23 : 05:35:02
you can't use SUM() with ORDER BY .... should be PARTITION BY


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-23 : 06:18:46
1) select EventDate ,ProductCd,CustomerNo ,sum(Quantity) OVER () AS RunningTotal
from #TableR
ORDER BY EventDate

2) select EventDate ,ProductCd,CustomerNo ,sum(Quantity) OVER ([red]partition by ColumnNames) AS RunningTotal
from #TableR
ORDER BY EventDate



--
Chandu
Go to Top of Page
   

- Advertisement -