The scenario is: I have 3 tables.
Commercial: NewPrice, OldPrice, Weight, Zone, ServiceType
Residential: NewPrice, OldPrice, Weight, Zone, ServiceType
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 TransactionReport.ServiceType, TransactionReport.Weight, TransactionReport.Zone, TransactionReport.Price, ResPrice.Contractprice, ResPrice.HistoricPrice, ResPrice.ServiceType, ResPrice.Weight, ResPrice.Zone
FROM TransactionReport, ResPrice
WHERE (((ResPrice.ServiceType)=[TransactionReport].[ServiceType]) AND ((ResPrice.Weight)=[TransactionReport].[Weight]) AND ((ResPrice.Zone)=[TransactionReport].[Zone]) AND ((([TransactionReport].[ServiceType]=[ResPrice].[ServiceType]) & ([TransactionReport].[Zone]=[ResPrice].[Zone]) & ([TransactionReport].[Weight]=[ResPrice].[Weight]))<>False));
Problems i am facing now:
I am able to match all the transactions with the same servce type from the transactions table to the residential table.
However, the query for some reason does not traverse to the next service type.
Also, wanted to know if there is a way for me to insert the if functionality. That is.. if ItIsRes = true then matc with res, otherwise match with com.?
Commercial: NewPrice, OldPrice, Weight, Zone, ServiceType
Residential: NewPrice, OldPrice, Weight, Zone, ServiceType
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 TransactionReport.ServiceType, TransactionReport.Weight, TransactionReport.Zone, TransactionReport.Price, ResPrice.Contractprice, ResPrice.HistoricPrice, ResPrice.ServiceType, ResPrice.Weight, ResPrice.Zone
FROM TransactionReport, ResPrice
WHERE (((ResPrice.ServiceType)=[TransactionReport].[ServiceType]) AND ((ResPrice.Weight)=[TransactionReport].[Weight]) AND ((ResPrice.Zone)=[TransactionReport].[Zone]) AND ((([TransactionReport].[ServiceType]=[ResPrice].[ServiceType]) & ([TransactionReport].[Zone]=[ResPrice].[Zone]) & ([TransactionReport].[Weight]=[ResPrice].[Weight]))<>False));
Problems i am facing now:
I am able to match all the transactions with the same servce type from the transactions table to the residential table.
However, the query for some reason does not traverse to the next service type.
Also, wanted to know if there is a way for me to insert the if functionality. That is.. if ItIsRes = true then matc with res, otherwise match with com.?