A
antgel
Hi all,
I'm implementing a database that tracks orders of items, delivery notes, and
invoices. I've tried to implement a dynamic system. What I mean by this is
that when you view an order, the price of each order line is calculated
on-the-fly. The beauty of this is that if a price changes for any reason,
there is no need to go and update every order containing that item.
There is also the (major!) caveat that each customer pays either cost,
retail, or wholesale price, and so the order line price depends on that as
well. Some customers have their own custom price list, and some have a
percentage discount. As this calculation is so complex, I implemented it in
a function:
Function getItemPrice(contactId_p As Long, lItemVariationId_p As Long)_
As Currency
The idea that you pass in the customer and item, and it returns the price
for one item for that customer. I then use this function in a query:
SELECT orderLine.orderLine, contact.contactid, orderLineQuantity.quantity,
getItemPrice([contactid],itemvariation.id) AS itemPrice,
[itemPrice]*[quantity] AS linePrice
FROM (contact INNER JOIN [order] ON contact.contactid = order.customerId)
INNER JOIN (itemVariation INNER JOIN (orderLine INNER JOIN orderLineQuantity
ON orderLine.orderLine = orderLineQuantity.orderLine) ON itemVariation.id =
orderLine.itemRef) ON order.id = orderLine.orderId;
The problem is speed. If I look at a continuous form with, say 20 lines on
it, I can see each record being calculated! Not only does this look crap,
the customer is not happy. Same applies if the form is scrolled, or if a
window on top is closed etc.
And, it's compounded. When I want order totals, and later invoice totals
(where by virtue of joins, the invoice references the order lines, and there
is a loooong wait.
I've decided that conceptually this _must_ be do-able in Jet SQL, and I hope
it would be much faster. The function opens up to 6 ADO Recordsets, which
I've heard is rather slow. Only problem is, I have no idea how to set up
the queries.
It might help to understand my data structures if I point out some of my
tables and _some_ relevant fields:
Contact(id, contactTypeId) - this field determines customer's price "type".
ContactType(id, description) e.g. (1,cost, 2,wholesale 3, retail).
ItemCommon(article, wholesalePrice, costPrice, retailPrice) - this table
contains the prices.
CustomPriceList(contactId, articleId, customPrice) - if the contact id is in
here - they pay customPrice.
Any help is appreciated as I'm tearing my hair out here! I hope I haven't
turned off all the SQL gurus by going into too much detail...
I should also point out that I've been working on this for months and I
wouldn't be surprised if there's a simple, elegant, fast solution.
Antony
I'm implementing a database that tracks orders of items, delivery notes, and
invoices. I've tried to implement a dynamic system. What I mean by this is
that when you view an order, the price of each order line is calculated
on-the-fly. The beauty of this is that if a price changes for any reason,
there is no need to go and update every order containing that item.
There is also the (major!) caveat that each customer pays either cost,
retail, or wholesale price, and so the order line price depends on that as
well. Some customers have their own custom price list, and some have a
percentage discount. As this calculation is so complex, I implemented it in
a function:
Function getItemPrice(contactId_p As Long, lItemVariationId_p As Long)_
As Currency
The idea that you pass in the customer and item, and it returns the price
for one item for that customer. I then use this function in a query:
SELECT orderLine.orderLine, contact.contactid, orderLineQuantity.quantity,
getItemPrice([contactid],itemvariation.id) AS itemPrice,
[itemPrice]*[quantity] AS linePrice
FROM (contact INNER JOIN [order] ON contact.contactid = order.customerId)
INNER JOIN (itemVariation INNER JOIN (orderLine INNER JOIN orderLineQuantity
ON orderLine.orderLine = orderLineQuantity.orderLine) ON itemVariation.id =
orderLine.itemRef) ON order.id = orderLine.orderId;
The problem is speed. If I look at a continuous form with, say 20 lines on
it, I can see each record being calculated! Not only does this look crap,
the customer is not happy. Same applies if the form is scrolled, or if a
window on top is closed etc.
And, it's compounded. When I want order totals, and later invoice totals
(where by virtue of joins, the invoice references the order lines, and there
is a loooong wait.
I've decided that conceptually this _must_ be do-able in Jet SQL, and I hope
it would be much faster. The function opens up to 6 ADO Recordsets, which
I've heard is rather slow. Only problem is, I have no idea how to set up
the queries.
It might help to understand my data structures if I point out some of my
tables and _some_ relevant fields:
Contact(id, contactTypeId) - this field determines customer's price "type".
ContactType(id, description) e.g. (1,cost, 2,wholesale 3, retail).
ItemCommon(article, wholesalePrice, costPrice, retailPrice) - this table
contains the prices.
CustomPriceList(contactId, articleId, customPrice) - if the contact id is in
here - they pay customPrice.
Any help is appreciated as I'm tearing my hair out here! I hope I haven't
turned off all the SQL gurus by going into too much detail...
I should also point out that I've been working on this for months and I
wouldn't be surprised if there's a simple, elegant, fast solution.
Antony