Hi,
So, Bud is not part of Q?
The way I now see the system is that we may want to update KlubbatBeloppSEK
with the maximum Budregistreringrad.Bud:
UPDATE Objekt
SET Objekt.KlubbatBeloppSEK = DMax("Dub", "Budregistreringrad",
"Objektmottagningrad =" & Objektmottagningrad )
Once the value is updated, then, we can look back in Budregistreringrad to
see from where it comes from (else, with its zero, or its default value,
that price of 0 may not appear in Budregistreringrad).
SELECT Q.*, T.*
FROM Objekt As Q INNER JOIN Budregistreringrad As T
ON T.Objektmottagningrad = Q.Objektmottagningrad
AND
T.Bud=Q.KlubbatBeloppSEK
WHERE T.BuddatumTid=
(SELECT MIN(V.BuddatumTid)
FROM Budregistreringrad As V
WHERE V.Objektmottagningrad = T.Objektmottagningrad
AND
V.Bud=T.Bud
)
So, in cases where there are many bids with the same price, the first one,
the MIN(BuddatumTid) is the one to associate with Objektmottagningrad. Note
that I assume Q.KlubbatBeloppSEK is already assigned to MAX(T.Bud), so, we
do not have to tell it again.
Hoping it may help,
Vanderghast, Access MVP
Hi
Hi again,
Thank you you put a lot of effort into this and I appreciate it very much.
Still just creates the Q with the below
SELECT Q.Objektmottagningrad, Q.Statusnr, Q.KlubbatBeloppSEK
FROM Objekt As Q
WHERE Bud =
(SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE BuddatumTid =
(SELECT Max(V.BuddatumTid)
FROM Budregistreringrad As V
WHERE V.Objektmottagningrad = Q.Objektmottagningrad))
I will try to explain a little deeper so you will be able to understand why
I need two subs.
Objekt is a table containing objekts for sale at a auction.
"Objektmottagningrad" is autonumber field. The auctioneer sets an estimate
(price) for every objekt for sale and there is a field called
"KlubbatBeloppSEK" (Hammer price, final price at the auction) This is
updated with a 0 if it is not sold. "Statusnr" is linked to a status table
to be able to show the correct status for the objekt...Sold, Not sold etc.
Budregistreringrad containing Bud (Bids) currency field and BuddatumTid is a
datetime field wich is updated wiht now() when the bid is endtered into the
system. If many bids with the same value on the same objekt then I use the
BuddatumTid to tell witch bid is the top/latest (winning Bid which I use to
update the hammer price with.All this fields are normally taken care of
automaticly in the system in different routines.
What I am trying to achive here is a way for the custumer to push the button
and get alot of work done automaticly..if planned auction has to be
inhibited late. All objekts and bids etc are registred into the system and
the has to be cancled. I need to have the query updatable use it as a
recordset and loop throw the records one by one and set the status, hammer
price = highest/latest bid etc etc.
Hope you understand me little better this time..
Mattias
Hi,
I don't understand the purpose of the second sub-query ( you have THREE
levels of SELECT. The intermediate SELECT seems un-necessary, I would remove
what is in red:
SELECT Q.Objektmottagningrad, Q.Statusnr, Q.KlubbatBeloppSEK
FROM Objekt As Q
WHERE Bud = (SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE BuddatumTid = (SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE T.Objektmottagningrad = Q.Objektmottagningrad))
Note that Bud should be in Q (in Objekt ); if it is not, make it so (in
green) :
SELECT Q.Objektmottagningrad, Q.Statusnr, Q.KlubbatBeloppSEK
FROM ( Objekt INNER JOIN Buddatum ON ... ) AS Q
WHERE Q.Bud= (SELECT Max(T.BuddatumTid) ...
My feeling is that is more what is probably in the nature of the problem,
at the moment, but...if you ever need three levels of SELECT, I repeat that
I really doubt it is where you should continue to look at, but if this is
what you need, you probably need to change the alias too, here, I used V
SELECT Q.Objektmottagningrad, Q.Statusnr, Q.KlubbatBeloppSEK
FROM Objekt As Q
WHERE Bud =
(SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE BuddatumTid =
(SELECT Max(V.BuddatumTid)
FROM Budregistreringrad As V
WHERE V.Objektmottagningrad = Q.Objektmottagningrad))
but again, taking the MAX of something already been take equal to a MAX is
not generally what we may look for (even if in this case, the group over
which you take the max is not the same in both cases).
Sorry that I can't get more "in" the problem, but "Objektmottagningrad"
and "Budregistreringrad" do not awake any meaning, any "second hint" about
the nature of the problem, so, I am left on the pure mathematical/mechanical
nature of the problem itself.
Hoping it may help,
Vanderghast, Access MVP
Mattias said:
Guess this is how it should look, but it still not working right...it does
not create Budregistreringrad As T so when running the query I does
not
find
Bud and BuddatumTid...do you know why this is happening?
SELECT Q.Objektmottagningrad, Q.Statusnr, Q.KlubbatBeloppSEK
FROM Objekt As Q
WHERE Bud = (SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE BuddatumTid = (SELECT Max(T.BuddatumTid)
FROM Budregistreringrad As T
WHERE T.Objektmottagningrad = Q.Objektmottagningrad))
currency
field
get
the this
sql aggregate) solution
and
the
amount
26
100
000,00
kr
2003-06-03 11:54:50
336 Interiör 30 000,00 kr
15
100
000,00
kr
2003-05-22 12:31:13
337 Kristallkrona 40 000,00 kr
000,00
is
only
record
1,000,000,
only