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
 Sum peices of order to get order total

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2008-07-03 : 11:11:11
I need to sum pieces of an order to get the order total. This total needs to be displayed on my site and included in an xml doc. Here's an example of what I have...

-Order-
orderID -pk
storeID

-OrderItem-
orderItemID -pk
orderID -fk
orderItemTypeID -fk
quantity

-OrderItemType-
orderItemTypeID - pk
dollarValue
isCoin



Basically, I need to sum dollarValue and isCoin for each orderID. How do I do this? Also, should I make this a stored procedure instead of doing the calculations on my site everytime?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-03 : 14:38:23
something like

SELECT o.orderid,SUM(oit.iscoin + oit.DollarValue)
FROM
order o
INNER JOIN
orderitem oi
ON
o.orderid = oi.orderid
INNER JOIN
orderitemtype oit
ON
oi.orderitemtypeid = oit.orderitemtypeid
GROUP BY o.order

Jim
Go to Top of Page
   

- Advertisement -