Hi Michel,
I am puiitng my SQL statement here so that will easy for you to understand
what i need do. Cause this is beyound my capasity!!!!!
SELECT Table1.ID, DWPRecord.Date, DWPRecord.ItemNo, ItemList.ItemName,
Table1.Lot, Table1.[S-Lot], Table1.HMAinSubLot, (SELECT SUM([HMAinSubLot])
FROM Table1 As A WHERE A.[Date]<=Table1.[Date] AND A.[ID]<=Table1.[ID]
AND
A.[ItemNo]=Table1.[ItemNo]) AS TotalHMA, -Int(-[TotalHMA]/5000) AS LotNo,
-Int(-[TotalHMA]/500) AS SubLotNo, Table1.Hwy, Table1.Dir, Table1.Lane,
Table1.Lift, Table1.RandomNo, Table1.RandomX, Table1.RandomY,
([HMAinSubLot]*[RandomNo]+([TotalHma]-[HMAinSubLot])) AS PST,
[PST]-(Nz((SELECT Sum([HMAinSubLot]) FROM Table1 As A WHERE
A.[Date]<Table1.[Date] AND A.[ID]<=Table1.[ID] AND
A.[ItemNo]=Table1.[ItemNo]),0)) AS PSToDayT,
[FrSta]+([PSToDayT]/([P-W]*[I-BRD]*([P-D]/1000))) AS PSSta,
DWPRecord.[I-BRD], DWPRecord.[P-W], DWPRecord.[P-D],
([TotalHMA]/([P-W]*([P-D]/1000)*[I-BRD])) AS LC, Table1.FrSta,
[FrSta]+[LC]
AS ToSta, ([LC]*[RandomX])+[Table1].[FrSta] AS CoreSta, [P-W]*[Randomy] AS
CoreOffset
FROM ItemList INNER JOIN (DWPRecord INNER JOIN Table1 ON DWPRecord.DWID =
Table1.ID) ON ItemList.ItemID = DWPRecord.ItemNo;
This query works good if road has only one lane. But highways has more
then
one lane. So If I change road lane or dirrection then my tosta
calculation
becomes wrong. Thats why I need to make toSta to become FrSta so if I
change
Lane then it worls ok.
Andy
Michel Walsh said:
As I understand it, no, since a record can have neither FromSta neither
ToSta, right? If so, that record is 'lost', unless you have ANOTHER FIELD
allowing to say where that record should be in relation to the other
records.
In a table of a database, records have no fixed position, in themselves.
They can move around, as, in example, when a 'data page split' occurs. On
the other hand, it the record ows a field like a date_time_stamp, or an
autonumber increasing sequentially without duplicated value, such field
can
effectively 'rank' the records among each others.
If either FromSta either ToSta is supplied, for any given record, then we
may be able to order, rank, the records accordingly to what is supplied.
---untested---
SELECT a.tonnage, a.length,
LAST(Nz( a.fromSta, Nz(MAX(b.toSta), MAX(b.fromSta)))) AS
computedFromSta,
LAST(Nz( a.toSta, Nz(MIN(c.toSta), MIN(c.fromSta)))) AS computedToSta
FROM (myTable AS a LEFT JOIN myTable As b
ON Nz(a.FromSta, a.ToSta) > Nz(b.FromSta), b.ToSta) )
LEFT JOIN myTable AS c
ON Nz(a.FromSta, a.ToSta) < Nz(c.FromSta), c.ToSta) )
GROUP BY a.tonnage, a.length, Nz( a.fromSta, a.toSta)
The logic behind is to get, under the alias b, all the records having
{fromSta, toSta} lower, so, before, the ones with alias a. The MAX
value
is thus the 'preceding' one. For alias c, the records with {fromSta,
toSta}
are those with an higher value, so after, the ones with alias a. So,
MIN(c.xxx) is the value closest 'succeeding' one. Since either fromSta,
either toSta can be null, we play a lor with Nz to circum-navigate that
indetermination... but again, at least ONE of the value, fromSta, or
toSta,
must be given, in any record.
Hoping it may help,
Vanderghast, Access MVP