Justin C Justin C - 1 year ago 65
SQL Question

Creating a table with one of the column values from an expression

I'm trying to create a table that I can use for Accounts Receivable. It's a very simple table, needing only the total cost of an order, how much has been paid into the order, and the order number itself. I'm trying to adapt an existing query used for report generation to do so.

[RushCharge],2) AS TotalCost,
[Sum Of Payments Query].[Total Payments],
[Order Details].RushCharge AS RushCharge,
INTO test2
FROM Orders
LEFT JOIN [Sum Of Payments Query]
ON Orders.OrderID = [Sum Of Payments Query].OrderID
GROUP BY Orders.OrderID,
[Sum Of Payments Query].[Total Payments],

The issue is the age of the DB, where the total cost of an order is always dynamically generated instead of being stored somewhere (Even though there is only one form that alters it, but still), meaning I have to resort to the same. The Round function calculates the total cost of the order, and it works elsewhere, but here, it just prompts me for values instead of pulling them from Orders.

What am I doing wrong? I know it has to be something simple.

Answer Source

I am guessing that [Quantity], [unit price] and [Discount] and RushCharge are fields in [order details] table, which is not included in the query.

you could create a query that returns the totalcost per order

select orderid,
            [RushCharge],2) AS TotalCost from 
from [order details]
group by orderid

and include this in your query in the same way you have [sum of Payments Query]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download