M
Matt Cromer
I have attached the sql to a query that I have developed. My question is
regarding the TraitHistory fields. I have to manually determine Curr and
Prev fields from my table and update the query. Is there a way to have the
query determine the Curr and Prev based on their position in the table. I am
usually wanting to compare the last column to the one before it. Am thinking
(but have not idea how to execute) count the columns in the table and use
that index to reference Max Column and Max Coulmn -1 these would be Curr and
Prev. I realize the table is messy in the respect that time are columns
(YearWKDay) (200835M) instead of rows. Any ideas of how I can do this?
SELECT Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr], TraitedItemDesc.[Item Desc
1], StrWhseAlignment.[Whse Nbr], StrWhseAlignment.[Whse Name],
Sum(TraitHistory.[200834M]) AS Prev, Sum(TraitHistory.[200835M]) AS Curr,
[TraitHistory]![200835M]-[TraitHistory]![200834M] AS Diff
FROM ((StrWhseAlignment RIGHT JOIN TraitHistory ON StrWhseAlignment.[Store
Nbr] = TraitHistory.[Store Nbr]) LEFT JOIN TraitedItemDesc ON
TraitHistory.[Item Nbr] = TraitedItemDesc.[Item Nbr]) LEFT JOIN
Weights_measures ON TraitHistory.[Item Nbr] = Weights_measures.[Item Nbr]
WHERE (((StrWhseAlignment.[Whse Nbr])<>0))
GROUP BY Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr], TraitedItemDesc.[Item Desc
1], StrWhseAlignment.[Whse Nbr], StrWhseAlignment.[Whse Name],
[TraitHistory]![200835M]-[TraitHistory]![200834M]
HAVING (((TraitedItemDesc.[Item Desc 1]) Is Not Null) AND
(([TraitHistory]![200835M]-[TraitHistory]![200834M])<>0))
ORDER BY Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr];
regarding the TraitHistory fields. I have to manually determine Curr and
Prev fields from my table and update the query. Is there a way to have the
query determine the Curr and Prev based on their position in the table. I am
usually wanting to compare the last column to the one before it. Am thinking
(but have not idea how to execute) count the columns in the table and use
that index to reference Max Column and Max Coulmn -1 these would be Curr and
Prev. I realize the table is messy in the respect that time are columns
(YearWKDay) (200835M) instead of rows. Any ideas of how I can do this?
SELECT Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr], TraitedItemDesc.[Item Desc
1], StrWhseAlignment.[Whse Nbr], StrWhseAlignment.[Whse Name],
Sum(TraitHistory.[200834M]) AS Prev, Sum(TraitHistory.[200835M]) AS Curr,
[TraitHistory]![200835M]-[TraitHistory]![200834M] AS Diff
FROM ((StrWhseAlignment RIGHT JOIN TraitHistory ON StrWhseAlignment.[Store
Nbr] = TraitHistory.[Store Nbr]) LEFT JOIN TraitedItemDesc ON
TraitHistory.[Item Nbr] = TraitedItemDesc.[Item Nbr]) LEFT JOIN
Weights_measures ON TraitHistory.[Item Nbr] = Weights_measures.[Item Nbr]
WHERE (((StrWhseAlignment.[Whse Nbr])<>0))
GROUP BY Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr], TraitedItemDesc.[Item Desc
1], StrWhseAlignment.[Whse Nbr], StrWhseAlignment.[Whse Name],
[TraitHistory]![200835M]-[TraitHistory]![200834M]
HAVING (((TraitedItemDesc.[Item Desc 1]) Is Not Null) AND
(([TraitHistory]![200835M]-[TraitHistory]![200834M])<>0))
ORDER BY Weights_measures.Brand, Weights_measures.Segment,
Weights_measures.Size, TraitHistory.[Item Nbr];