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
 Aggregate Question

Author  Topic 

rlull
Starting Member

39 Posts

Posted - 2006-07-06 : 10:44:59
How can I return the following information? The aggregate function is throwing it off. Is there a better way? Thanks.

select
Orders.OrderID,
Orders.OrderDateTime,
Orders.BillLastName,
Orders.BillCompany,
Orders.SubtTotal,
Orders.DiscountTotal,
Orders.Tax,
Orders.ShipCost,
Orders.OrderTotal,
Sum(Orders.SubTotal - Orders.DiscountTotal) as ActualMerchandise
Customers.SalesID

from Orders
join Customers
on Orders.CustID = Customers.CustID
where OrderDateTime >= '6/1/2006'
and OrderDateTime <= '6/30/2006'
order by SalesID, OrderDateTime

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-07-06 : 10:51:14
You forgot to add GROUP BY clause...


select
Orders.OrderID,
Orders.OrderDateTime,
Orders.BillLastName,
Orders.BillCompany,
Orders.SubtTotal,
Orders.DiscountTotal,
Orders.Tax,
Orders.ShipCost,
Orders.OrderTotal,
Sum(Orders.SubTotal - Orders.DiscountTotal) as ActualMerchandise
Customers.SalesID

from Orders
join Customers
on Orders.CustID = Customers.CustID
where OrderDateTime >= '6/1/2006'
and OrderDateTime <= '6/30/2006'
group by
Orders.OrderID,
Orders.OrderDateTime,
Orders.BillLastName,
Orders.BillCompany,
Orders.SubtTotal,
Orders.DiscountTotal,
Orders.Tax,
Orders.ShipCost,
Orders.OrderTotal,
Customers.SalesID
order by SalesID, OrderDateTime



Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-06 : 11:00:41
when you say "throwing it off", you mean like not even running?

You need the group by like what has been posted...unless you are trying to do something entirely different...which is what my spidy sense is telling me



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -