PC Review


Reply
Thread Tools Rate Thread

change price in table w/out changing price in past records

 
 
=?Utf-8?B?a2luYmVybHk=?=
Guest
Posts: n/a
 
      7th Nov 2003
I am trying to figure out how, in the Northwind example, the prices go up in the product table, but the detail for past orders maintains the previous price.

When I change the price in my table, all my orders that I previously entered, the price changes as well.

Any help would be greatly appreciated!
 
Reply With Quote
 
 
 
 
Gert-Jan van der Kamp
Guest
Posts: n/a
 
      8th Nov 2003
I'm not familiar with the northwind database, but here's the idea:

You can make another table called PriceHistory, with the fields ProductKey,
Price, StartDate. The primairykey is the three columns together. The
pricefield is now no longer in the products table but in this table. Here
you can enter new prices with their startingdate so you keep a history of
all the prices. To join a price to a product you use:

SELECT
Products.Name,
Max(PriceHistory.Price) AS Price
FROM
Products INNER JOIN PriceHistory ON Products.Key =
PriceHistory.ProductKey
WHERE PriceHistory.StartDate<=Date()
GROUP BY Products.Name;

The same goed for orders, but then you join the orders table in there as
well and the whereclause becomes:
WHERE PriceHistory.Startdate<=Orders.OrderDate

Hope this helps,

Regards Gert-Jan

"kinberly" <(E-Mail Removed)> schreef in bericht
news:A12D9DFD-EF4F-4594-BDBB-(E-Mail Removed)...
> I am trying to figure out how, in the Northwind example, the prices go up

in the product table, but the detail for past orders maintains the previous
price.
>
> When I change the price in my table, all my orders that I previously

entered, the price changes as well.
>
> Any help would be greatly appreciated!



 
Reply With Quote
 
Gert-Jan van der Kamp
Guest
Posts: n/a
 
      8th Nov 2003
Oops, BIG Mistake. (it's been a while) Forget the previous message!

This is it:
Make a new tabel called PriceHistory with the following fields:
ProductKey Numeric :Foreignkey of the related product
StartDate Date/Time ate that the price was raised(or
lowered) to the price in this record
Price Currency :The price

Make the first two columns the primairy key. (don't forget or this will be a
slow query.) If you also make a relationship between the ProductKey in this
table and the Key column in the products table you get to use the nifty
subdatasheet feature so it's easier to use this all.

In this table, you keep a log of all the prices that ever were for this
product with their startingdate. For the current price of an item use the
following query:

SELECT
Products.Name,
PriceHistory.Price AS Price
FROM
Products INNER JOIN PriceHistory ON
Products.Key = PriceHistory.ProductKey
WHERE
PriceHistory.StartDate=(SELECT MAX(StartDate) FROM PriceHistory WHERE
PriceHistory.ProductKey = Products.Key AND StartDate<=Date());


When you want to find the price for an order, inner join products,
pricehistory, orders and orderlines (i presume it's like this) and the
instead of the "date()" function at the end type "Orders.Date" So you take
the price for the day the order was placed instead of today. Hope this
helps.

GJ



"Gert-Jan van der Kamp" <gjvdkamp[@spam]hotmail.com> schreef in bericht
news:boijdg$sjs$(E-Mail Removed)...
> I'm not familiar with the northwind database, but here's the idea:
>
> You can make another table called PriceHistory, with the fields

ProductKey,
> Price, StartDate. The primairykey is the three columns together. The
> pricefield is now no longer in the products table but in this table. Here
> you can enter new prices with their startingdate so you keep a history of
> all the prices. To join a price to a product you use:
>
> SELECT
> Products.Name,
> Max(PriceHistory.Price) AS Price
> FROM
> Products INNER JOIN PriceHistory ON Products.Key =
> PriceHistory.ProductKey
> WHERE PriceHistory.StartDate<=Date()
> GROUP BY Products.Name;
>
> The same goed for orders, but then you join the orders table in there as
> well and the whereclause becomes:
> WHERE PriceHistory.Startdate<=Orders.OrderDate
>
> Hope this helps,
>
> Regards Gert-Jan
>
> "kinberly" <(E-Mail Removed)> schreef in bericht
> news:A12D9DFD-EF4F-4594-BDBB-(E-Mail Removed)...
> > I am trying to figure out how, in the Northwind example, the prices go

up
> in the product table, but the detail for past orders maintains the

previous
> price.
> >
> > When I change the price in my table, all my orders that I previously

> entered, the price changes as well.
> >
> > Any help would be greatly appreciated!

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Need Excel formula to return correct price from price history table Ian_W-at-GMail Microsoft Excel Misc 6 21st Mar 2007 06:45 PM
Copy latest price to form and update price history =?Utf-8?B?c3BhY2Vyb2NrZXQ=?= Microsoft Access Forms 0 4th Apr 2006 04:35 AM
calculate/convert volume price to monthly average price =?Utf-8?B?QnVsdGdyZW4=?= Microsoft Excel Worksheet Functions 2 14th Feb 2006 09:36 AM
Structure for a Changing Price Lookup Table =?Utf-8?B?U0Ft?= Microsoft Access 3 22nd Aug 2005 08:27 PM
Price change, find correct price for date Bill Microsoft Access Reports 0 13th Dec 2003 02:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 AM.