Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

calculate the total price

Posted on 2008-11-11
4
Medium Priority
?
164 Views
Last Modified: 2012-05-05
Hello Experts,

I have a query which pulls information on the orders sent until today, Please can someone help me in finding the sum ordertotal, sum of ordershipping  and sum of orderlineprice

All I wanted the total amount between 1-sep-2007 to 31-aug-08

your help is greatly appreciated

thanks
kay
SELECT     dbo.[Order].OrderID, dbo.[Order].OrderDate, dbo.[Order].OrderTotal, dbo.[Order].OrderShipping, dbo.OrderDetail.OrderLineProdName, 
                      dbo.OrderDetail.OrderLineQty, dbo.OrderDetail.OrderLineIncVAT, dbo.OrderDetail.RowID, dbo.OrderDetail.OrderLinePrice
FROM         dbo.[Order] INNER JOIN
                      dbo.OrderDetail ON dbo.[Order].OrderID = dbo.OrderDetail.OrderID
WHERE     (dbo.[Order].OrderIncludeInWeeklySummary = 0)

Open in new window

0
Comment
Question by:learningnet
  • 2
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 1000 total points
ID: 22932636
SELECT
      dbo.[Order].OrderID,
      dbo.[Order].OrderDate,
      dbo.[Order].OrderTotal,
      dbo.[Order].OrderShipping,
      dbo.OrderDetail.OrderLineProdName,
      dbo.OrderDetail.OrderLineQty,
      dbo.OrderDetail.OrderLineIncVAT,
      dbo.OrderDetail.RowID,
      dbo.OrderDetail.OrderLinePrice,
      a.*
FROM
      dbo.[Order]
      INNER JOIN dbo.OrderDetail ON dbo.[Order].OrderID = dbo.OrderDetail.OrderID
      INNER JOIN (
                  select
                        orderid,
                        sum(ordertotal) as ordertotal,
                        sum(ordershipping) as ordershippingtotal,
                        sum(orderlineprice) as orderlinepricetotal
                  from
                        orderdetail
                  group by
                        orderid
                 ) a ON [Order].OrderID = a.[OrderID]
WHERE
      (dbo.[Order].OrderIncludeInWeeklySummary = 0)
0
 
LVL 61

Assisted Solution

by:Kevin Cross
Kevin Cross earned 1000 total points
ID: 22932778
Or something ike this if you only want the sum through period you specified.
SELECT    SUM(dbo.[Order].OrderTotal) AS SumOrderTotal
, SUM(dbo.[Order].OrderShipping) AS SumOrderShipping
, SUM(dbo.OrderDetail.OrderLinePrice) AS SumOrderLinePrice
FROM         dbo.[Order] INNER JOIN
                      dbo.OrderDetail ON dbo.[Order].OrderID = dbo.OrderDetail.OrderID
WHERE     (dbo.[Order].OrderIncludeInWeeklySummary = 0)
AND dbo.[Order].OrderDate >= '2007-09-01 00:00:00' AND dbo.[Order].OrderDate < '2008-09-01 00:00:00'

Open in new window

0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22932786
Good addition Kevin...wasn't sure if the author wanted to keep the current detail they had or not.  I almost wrote the same thing you just did.  ;)
0
 
LVL 61

Expert Comment

by:Kevin Cross
ID: 22933394
:) Yes, I am not sure either.  Think what you wrote is good too.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question