473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Order and Order Details Query trouble

I have created a database, using Northwind as a foundation. It is used to create purchase orders and analyse costs of various machines for a given period.
My order form is very similar to that in Northwind - it has an Order Details subform. Ihave recently added a Transport Costs field to the Order form. (Each separate Order is for one machine only). My Purchase Order report prints perfectly (akin to the Invoice report in NW). The problem lies when I try to print my Plant Costs report. This report calculates all of the items that were bought for a machine between two specified dates. It was fine until I added the Transport Costs field. Should there be four items on Order 18, say, for Machine 3, then these three products and their costs are sent to the report. Problems arise because the Transport Costs are then trebled - each Order Detail takes on the full Transport Cost. Is there any way of forcing my query to take the first instance of the Transport Costs only.

Any help is absolutely gratefully accepted!

Paul.

PS: I am just using a Design View query - just ticking the boxes. Criteria would be nice.

Thanks again.
Dec 20 '06 #1
18 2847
MMcCarthy
14,534 Expert Mod 8TB
I have created a database, using Northwind as a foundation. It is used to create purchase orders and analyse costs of various machines for a given period.
My order form is very similar to that in Northwind - it has an Order Details subform. Ihave recently added a Transport Costs field to the Order form. (Each separate Order is for one machine only). My Purchase Order report prints perfectly (akin to the Invoice report in NW). The problem lies when I try to print my Plant Costs report. This report calculates all of the items that were bought for a machine between two specified dates. It was fine until I added the Transport Costs field. Should there be four items on Order 18, say, for Machine 3, then these three products and their costs are sent to the report. Problems arise because the Transport Costs are then trebled - each Order Detail takes on the full Transport Cost. Is there any way of forcing my query to take the first instance of the Transport Costs only.

Any help is absolutely gratefully accepted!

Paul.

PS: I am just using a Design View query - just ticking the boxes. Criteria would be nice.

Thanks again.
Sorry Paul I'm afraid we'll have to see the query. In Design view can you change the view to SQL and copy and paste the code here.

Mary
Dec 21 '06 #2
Expand|Select|Wrap|Line Numbers
  1. SELECT Orders.OrderDate, Plant.PlantID, Plant.Make, Plant.Model, [Order Details].Quantity, Orders.OrderID, Products.ProductName, Products.UnitPrice, [Quantity]*[UnitPrice] AS Subtotal, Orders.Transport
  2. FROM Products INNER JOIN (Plant INNER JOIN ((Orders INNER JOIN [Transport Query] ON Orders.OrderID = [Transport Query].OrderID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Plant.PlantID = Orders.PlantID) ON Products.ProductID = [Order Details].ProductID
  3. WHERE (((Orders.OrderDate) Between [Start Date] And [End Date]) AND ((Plant.PlantID)=[Enter Plant ID]))
  4. ORDER BY Orders.OrderDate;

Please excuse any crudeness. Thanks for all efforts and merry christmas.
Paul.
Dec 22 '06 #3
I tried to bypass the problem by creating a Transport Query containing the Average of the Transport costs but I feel I was being a bit too clever...
Dec 22 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
Assuming Orders.Transport is the transport costs field you're refering to.

Expand|Select|Wrap|Line Numbers
  1. SELECT Orders.OrderDate, Plant.PlantID, Plant.Make, Plant.Model, [Order Details].Quantity, Orders.OrderID, Products.ProductName, Products.UnitPrice, [Quantity]*[UnitPrice] AS Subtotal, First(Orders.Transport)
  2. FROM Products INNER JOIN (Plant INNER JOIN ((Orders INNER JOIN [Transport Query] ON Orders.OrderID = [Transport Query].OrderID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Plant.PlantID = Orders.PlantID) ON Products.ProductID = [Order Details].ProductID
  3. WHERE (((Orders.OrderDate) Between [Start Date] And [End Date]) AND ((Plant.PlantID)=[Enter Plant ID]))
  4. GROUP BY Orders.OrderDate, Plant.PlantID, Plant.Make, Plant.Model, [Order Details].Quantity, Orders.OrderID, Products.ProductName, Products.UnitPrice, [Quantity]*[UnitPrice]
  5. ORDER BY Orders.OrderDate;
  6.  
Mary
Dec 22 '06 #5
Orders.Transport is the Transport field referred to. Unfortunately this has not fixed my problem. As my report lists the each of the Order Details of each Order, the Transport cost is added in each time.

An example of a Cost Report could be:
Plant 20 has had 3 products purchased for on Order 18 - Transport 100, and 1 product on Order 33 - Transport 50.

The main body of the report looks something like this:

Expand|Select|Wrap|Line Numbers
  1. OrderID   Product        Quantity     Price    Subtotal
  2.    18        XXXXX               2              5           10
  3.    18        YYYY               1              3            3
  4.    18        ZZZZZ               2              2            4
  5.    33        PPPP               1              5            5
  6.  
  7.                                             Transport Costs 350
  8.                                             Total                 372
My problem is that each Order Detail adds the full Transport Cost to the Total.
I need Transport Costs to be added once only for each Order.
The true Transport Costs should be 150. Therefore the true Total should be 172.

Paul.
Dec 29 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
This sounds like a grouping problem. What are the formulas being used in the following and what footers are they in

Transport Costs 350
Total 372


Mary
Jan 1 '07 #7
The Transport Costs formula is =Sum([FirstOfTransport])
The Total is =Sum([Subtotal])+Sum([FirstOfTransport]).

They are both in the PlantID footer. I only have PlantID Header and Footer turned on.

Each Plant has its own separate report, starting on a new page.

In the Report Footer I have an Overall Total which is supposed to sum the total for each Plant and true Transport Costs to give one final figure for the boss. He doesn't want to know the rest!

By the way, is there any simple way of selecting a group of reports to print, say PlantIDs 1,4,7 and 9, instead of having to print them out separately. I have already this single PlantID printing set up.


PS
Thanks for all of your help and Happy New Year.
Jan 1 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
The Transport Costs formula is =Sum([FirstOfTransport])
The Total is =Sum([Subtotal])+Sum([FirstOfTransport]).
Not sure I understand

You said you didn't want transport costs included in the total but you've put them in the calculation
Jan 2 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
Ok, try the following ....

change your query to this.

Expand|Select|Wrap|Line Numbers
  1. SELECT Orders.OrderDate, Plant.PlantID, Plant.Make, Plant.Model, [Order Details].Quantity, Orders.OrderID, Products.ProductName, Products.UnitPrice, [Quantity]*[UnitPrice] AS Subtotal, Orders.Transport
  2. FROM Products INNER JOIN (Plant INNER JOIN ((Orders INNER JOIN [Transport Query] ON Orders.OrderID = [Transport Query].OrderID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Plant.PlantID = Orders.PlantID) ON Products.ProductID = [Order Details].ProductID
  3. WHERE (((Orders.OrderDate) Between [Start Date] And [End Date]) AND ((Plant.PlantID)=[Enter Plant ID]))
  4. ORDER BY Orders.OrderDate;
  5.  
Then create a second group on the report for orderID with header and footer. Then come back to me.
Jan 2 '07 #10
In order to find the total costs for the Plant, Transport must be factored in. An afterthought by the crowd who want the database, I'm afraid.

This last query does show the correct Transport Costs for each OrderID:
(In the example I test stuff on there are 4 items in Order 18 and 1 in Order 3. The report now shows Transport Costs to be €100 for Order 18 and €300 for Order 33. Normally (when I did it!) these would be €400 and €300, respectively. These values now have to be factored into the Total for the Plant, and then into the Final total (the sum of all of the Plant totals plus the sum of all of the Order Transport costs).

How now will I add the correct Transport Costs to the Plant totals?
Jan 2 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
In order to find the total costs for the Plant, Transport must be factored in. An afterthought by the crowd who want the database, I'm afraid.

This last query does show the correct Transport Costs for each OrderID:
(In the example I test stuff on there are 4 items in Order 18 and 1 in Order 3. The report now shows Transport Costs to be €100 for Order 18 and €300 for Order 33. Normally (when I did it!) these would be €400 and €300, respectively. These values now have to be factored into the Total for the Plant, and then into the Final total (the sum of all of the Plant totals plus the sum of all of the Order Transport costs).

How now will I add the correct Transport Costs to the Plant totals?
In the plant footer you should be able to total the costs in the order footer
Jan 2 '07 #12
It's still giving the Transport total as €700. Costs are being displayed correctly using the OrderID footer but the number of items in the order are being multiplied by the transport cost when it comes to getting the Transport total.
In the OrderID footer I have [Transport].
In the PlantID footer I have =Sum([Transport]).

Is there an arithmetic function, other than Sum, that allows the average of a field to be summed? And would it work [if there is]?
Jan 2 '07 #13
MMcCarthy
14,534 Expert Mod 8TB
It's still giving the Transport total as €700. Costs are being displayed correctly using the OrderID footer but the number of items in the order are being multiplied by the transport cost when it comes to getting the Transport total.
In the OrderID footer I have [Transport].
In the PlantID footer I have =Sum([Transport]).
In the PlantID footer you should have

=Sum([Name of Control in OrderID Footer])

Mary
Jan 3 '07 #14
I have named the Text box in the OrderID footer "Courier", so as to avoid any ambiguity. When I ask it to =Sum([Courier]), I get prompted to enter a value for Courier. Is this what you meant by =Sum([Name of Control in OrderID Footer]), or is there a specific way to call on Controls?
Jan 3 '07 #15
MMcCarthy
14,534 Expert Mod 8TB
I have named the Text box in the OrderID footer "Courier", so as to avoid any ambiguity. When I ask it to =Sum([Courier]), I get prompted to enter a value for Courier. Is this what you meant by =Sum([Name of Control in OrderID Footer]), or is there a specific way to call on Controls?
Open the properties window for the Courier control and under the other tab what is the value in the Name property. This is what you should use.

Mary
Jan 3 '07 #16
The name under the Other tab is Courier. I'm still being prompted for Courier. I put in "1" as a test, and the Total Transport Costs were given as 5, though the individual costs for order 18 is 100, and for order 33 is 300. There are four items in order 18 and one in order 33.
Jan 4 '07 #17
MMcCarthy
14,534 Expert Mod 8TB
I have named the Text box in the OrderID footer "Courier", so as to avoid any ambiguity. When I ask it to =Sum([Courier]), I get prompted to enter a value for Courier. Is this what you meant by =Sum([Name of Control in OrderID Footer]), or is there a specific way to call on Controls?
Ok, Access reports can have problems summing on calculated controls. Put another control in OrderID footer and set control source to =[Courier].

Now try summing this control instead.

Mary
Jan 5 '07 #18
No joy. The Transport sum is still including the full transport cost for each item on the order although the costs are being displayed properly on the report.
Jan 6 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: peter pilsl | last post by:
postgres 7.3.2 I store unicode-data in postgresql. The data is retrieved via webinterfaces, processed with perl and then stored in postgresql (and viceversa). All is going nice with one...
5
by: javier garcia - CEBAS | last post by:
Hi, I'm not an expert, not by far. I've just installed postgres7.4 and have realized tat the order of rows in queries in different to that in 7.3.4. It seems that previously it was more logic,...
2
by: Hohn Upshew | last post by:
I need some help to build a report enumerating the products in descending order depending on the sum of liters. In this way i can view the top products sold for a given period.But i fail to do...
7
by: Not Me | last post by:
Hi, Having a table with some duplicate ID's (different data tho), how can I return the list but with only one record from each ID? Would this be using the first() function and grouping? ...
5
by: Ataru Morooka | last post by:
Hi, my table has to have a column with the months names (january, february...). When I order it by month it is ordered alphabetically and that's not what I need. Reading this ng I found someone...
4
by: dtwalter | last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't be, but I'm having some trouble. Hopefully it's just a simple error in syntax and somebody can tell me. Here's what I'm trying...
3
by: Student at college | last post by:
Something is wrong with my report in Access. In the query for the report I have an order by clause. However, when I run the report, it comes out in a different order. Is there something else...
1
by: Diggar | last post by:
I have a data base with about 4 different tables. 1. Cust info 2. Supplier info 3. Order History 4. Order details. Order history and details are on one form with details being the subform....
25
by: DanicaDear | last post by:
Hello again Bytes...I missed you! First, background: In a hotstick lab, we ship orders every two years. We ship a new order and the customer uses the new box to return the previous year's order....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.