Available prices (1 Viewer)

Mihail

Registered User.
Local time
Today, 15:44
Joined
Jan 22, 2011
Messages
2,373
Hello !

As you know, the prices are, unfortunately, dynamic "objects".

So, I have a table for products:
tblProducts
ID_Product - Autonumber (PK)
ProductName

and a table for prices
tblProductsPrices
ID_ProductPrice - Autonumber (PK)
ID_Product - Number (FK on tblProducts
Price - Double
PriceDate - Date/Time

The problem:
I have a certain date.
I need to know the available prices at that date for all products.

Thank you !

PS_1
I have a solution; but, for each product, I apply an external function that use two aggregate functions: DMax and Dlookup

For my small tables, this isn't a problem but I like to know if it is a better way.

PS_2
Note, please, that my skills are quite nulls regarding the SQL.
So, try to design for me something that I can see in Queries Design View.
 

Attachments

  • PricesQuestion.mdb
    284 KB · Views: 61

WayneRyan

AWF VIP
Local time
Today, 13:44
Joined
Nov 19, 2002
Messages
7,122
Mihail,

You'll need a couple of queries. This is still WAY faster than using the Domain functions. Assume you have the date on some form:

Code:
Query1:
Select ID_Product, PriceDate
From   tblProductsPrices
Where  PriceDate < Forms!SomeForm!TheDate

Query2:
Select ID_Product, Max(PriceDate) As ThePrice
From   Query1
Group By ID_Product

Finally:
Select A.ID_Product, B.ThePrice
From   tblProducts As A Inner Join Query2 As B On
          a.ID_Product = b.ID_Product

Wayne
 

Geotch

Registered User.
Local time
Today, 07:44
Joined
Aug 16, 2012
Messages
154
If Wayne Ryan's post doesn't help, I can upload a sample.
 

Mihail

Registered User.
Local time
Today, 15:44
Joined
Jan 22, 2011
Messages
2,373
@Wayne
Your Query3 has as the result the dates, not the prices.
Q: Is there any way to obtain A and B without directly manipulate the SQL ?

@Geo
Thank you for the offer.
Anyone, anytime, is welcome in my threads.
So, I like to see your solution.

@Anyone
I'll not implement a solution based on SQL strings because I'll not be able to adapt , to debug or to maintain my DB.
That don't mean that I don't like to see a solution like this. Maybe I can learn something.

Thank you all !
 

WayneRyan

AWF VIP
Local time
Today, 13:44
Joined
Nov 19, 2002
Messages
7,122
Mihail,

Sorry, I forgot a part:

Code:
Query1:
Select ID_Product, PriceDate
From   tblProductsPrices
Where  PriceDate < Forms!SomeForm!TheDate

Query2:
Select ID_Product, Max(PriceDate) As TheDate
From   Query1
Group By ID_Product

Finally:
Select A.ID_Product, B.TheDate, C.Price
From   tblProducts As A Inner Join Query2 As B On
          a.ID_Product = b.ID_Product Inner Join tblProductPrices as C On
              B.ID_Product = C.ID_Product And
              B.TheDate = C.PriceDate

You can paste these into the Access Query Editor. They're not meant to
be run as VBA.

Wayne
 

spikepl

Eledittingent Beliped
Local time
Today, 14:44
Joined
Nov 3, 2010
Messages
6,142
Remember to put index on the price dates
 

Mihail

Registered User.
Local time
Today, 15:44
Joined
Jan 22, 2011
Messages
2,373
@Wayne
Sorry. Still not work. And, as I said, I am not able to debug :(
 

Attachments

  • PricesError.JPG
    PricesError.JPG
    19.9 KB · Views: 50

JHB

Have been here a while
Local time
Today, 14:44
Joined
Jun 17, 2012
Messages
7,732
Try if it satisfied your requirement:
Input at date in your form, and the run Query2.
 

Attachments

  • PricesQuestion.mdb
    544 KB · Views: 59

Mihail

Registered User.
Local time
Today, 15:44
Joined
Jan 22, 2011
Messages
2,373
Try if it satisfied your requirement:
Input at date in your form, and the run Query2.

That was, JHB.
One more thank you because, now, I have a template for things like this one.
 

Mihail

Registered User.
Local time
Today, 15:44
Joined
Jan 22, 2011
Messages
2,373
How can that be?

Unfortunately, is true.
All I can do is to design very simple "Where" clauses in order to filter a form, a report or a domain function.
 

Users who are viewing this thread

Top Bottom