The scenario is: I have 3 tables.
Commercial: NewPrice, OldPrice, Weight, Zone
Residential: NewPrice, OldPrice, Weight, Zone
TransactionReport: Price, Weight, Zone, IsItRes (a boolean)
Task at hand: Write a query, which takes all the records in the transaction table, first of all checks whether it is a residential or Commercial by looking at IsItRes field in the TransactionReport table.
If a specific record is a residential delivery, then matches the service type, weight and zone in the TransactionReport table to the Residential table and displays the Weight, Zone, Price, NewPrice from Residential table and OldPrice from Residetial table.
If record is not residential, then prints similar information from the commercial table.
I have attched my SQL code, any help or suggestions to improve logic will be greatly appreciated.
SELECT IIf ((TransactionReport.IsItRes) = TRUE),
(TransactionReport.Zone, TransactionReport.Weight, TransactionReport.Price, ResPrice.ContractPrice, ResPrice.HistoricPrice), (TransactionReport.Zone, TransactionReport.Weight, TransactionReport.Price, ComPrice.ContractPrice, ComPrice.HistoricPrice)
FROM TransactionReport, ResPrice, ComPrice
Where (((TransactionReport.Zone = ResPrice.Zone) & (TransactionReport.weight = ResPrice.Weight)) OR ((TransactionReport.Zone = ComPrice.Zone) & (TransactionReport.weight = ComPrice.Weight)))
Thanks,
kam
Commercial: NewPrice, OldPrice, Weight, Zone
Residential: NewPrice, OldPrice, Weight, Zone
TransactionReport: Price, Weight, Zone, IsItRes (a boolean)
Task at hand: Write a query, which takes all the records in the transaction table, first of all checks whether it is a residential or Commercial by looking at IsItRes field in the TransactionReport table.
If a specific record is a residential delivery, then matches the service type, weight and zone in the TransactionReport table to the Residential table and displays the Weight, Zone, Price, NewPrice from Residential table and OldPrice from Residetial table.
If record is not residential, then prints similar information from the commercial table.
I have attched my SQL code, any help or suggestions to improve logic will be greatly appreciated.
SELECT IIf ((TransactionReport.IsItRes) = TRUE),
(TransactionReport.Zone, TransactionReport.Weight, TransactionReport.Price, ResPrice.ContractPrice, ResPrice.HistoricPrice), (TransactionReport.Zone, TransactionReport.Weight, TransactionReport.Price, ComPrice.ContractPrice, ComPrice.HistoricPrice)
FROM TransactionReport, ResPrice, ComPrice
Where (((TransactionReport.Zone = ResPrice.Zone) & (TransactionReport.weight = ResPrice.Weight)) OR ((TransactionReport.Zone = ComPrice.Zone) & (TransactionReport.weight = ComPrice.Weight)))
Thanks,
kam