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
 Cannot perform an aggregate function on an express

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-24 : 10:26:46
I am getting error by execuiting below query, I need to calculate the percentage. Can you please help me on this by modifying the query.



select oe2.OrdSourceID,Count(oe2.OrdSourceID) as TotalOrders,
Percentage = Count(oe2.OrdSourceID) * 100.0 / SUM(Count(oe2.OrdSourceID))
from OeOrders Oe
iNNER JOIN OeOrders2 AS oe2
ON Oe.OrderID = oe2.OrderID
where
Oe.ProviderID = 'JOHN' and Oe.OrderDateTime between '10/07/2014' and '10/15/2014' and oe2.OrdSourceID is not null
AND Oe.[Status] NOT IN ( 'CANCEL', 'CANC', 'CNC', 'UNVER', 'UNV' )
Group by oe2.OrdSourceID



Thanks..

Archana

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-24 : 10:51:09
Help me plzzzzzzzzzzzzzz

Archana
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-10-25 : 15:38:12
you mean this?

select oe2.OrdSourceID,Count(oe2.OrdSourceID) as TotalOrders,
Percentage = Count(oe2.OrdSourceID) * 100.0 / SUM(Count(oe2.OrdSourceID)) OVER ()
from OeOrders Oe
iNNER JOIN OeOrders2 AS oe2
ON Oe.OrderID = oe2.OrderID
where
Oe.ProviderID = 'JOHN' and Oe.OrderDateTime between '10/07/2014' and '10/15/2014' and oe2.OrdSourceID is not null
AND Oe.[Status] NOT IN ( 'CANCEL', 'CANC', 'CNC', 'UNVER', 'UNV' )
Group by oe2.OrdSourceID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -