CarlRostron
Registered User.
- Local time
- Today, 22:38
- Joined
- Nov 14, 2011
- Messages
- 88
I have two tables.
tblTrafficFormat (This tables lists all the possible formats available):
TrafficFormatID, Format, SummaryFormat
(I am happy this table has the correct info within it)
tblTrafficNational (This table lists all the volumes by Office where each volume is a particular format)
TrafficID, OfficeID, TrafficFormatID, DateID, TrafficVolume
(I am happy this table has the correct info within it)
Problem:
I want to run a query which gives me the Summed Volumes by Office by Format from tblTrafficNational. The problem is that there are offices with volumes in this table which dont have ALL format listed from the traffic table. I want to include ALL formats in my query even if they sum to zero.
Currently I am running the following LEFT OUTER join but it doesnt work for me:
This is the SQL I am running:
This is the output I am getting but I want to see ALL formats and zeros where appropriate and there are 14 formats in the formats table not 7 that are shown below:
Query3OfficeIDTrafficFormatIDSumOfTrafficVolume1110063Delivered Walksorted Letters35199611110063Delivered Walksorted Flats8704101110063Delivered Sequenced Letters26599101110063Delivered Manual Letters1339561110063Delivered Packets17869101110063Delivered Special Delivery1910331110063Delivered Walksorted Packets1185504
The current tblTrafficFormat Table is:
tblTrafficFormatTrafficFormatIDFormatSummary FormatWeighting1Delivered Walksorted LettersLetters0.372Delivered Walksorted FlatsFlats0.533Delivered Sequenced LettersLetters0.314Delivered Manual LettersLetters0.535Delivered FlatsFlats0.766Delivered PacketsParcels3.077Delivered RM TrackedTracked7.668Delivered Special DeliverySD6.919Delivered Walksorted PacketsParcels1.9410LettersLetters
11FlatsFlats
12ParcelsParcels
13SDSD
14TrackedTracked
Please help.
tblTrafficFormat (This tables lists all the possible formats available):
TrafficFormatID, Format, SummaryFormat
(I am happy this table has the correct info within it)
tblTrafficNational (This table lists all the volumes by Office where each volume is a particular format)
TrafficID, OfficeID, TrafficFormatID, DateID, TrafficVolume
(I am happy this table has the correct info within it)
Problem:
I want to run a query which gives me the Summed Volumes by Office by Format from tblTrafficNational. The problem is that there are offices with volumes in this table which dont have ALL format listed from the traffic table. I want to include ALL formats in my query even if they sum to zero.
Currently I am running the following LEFT OUTER join but it doesnt work for me:
This is the SQL I am running:
Code:
SELECT tblTrafficNational.OfficeID, tblTrafficNational.TrafficFormatID, Sum(tblTrafficNational.TrafficVolume) AS SumOfTrafficVolume
FROM tblTrafficFormat LEFT JOIN tblTrafficNational ON tblTrafficFormat.TrafficFormatID = tblTrafficNational.TrafficFormatID
GROUP BY tblTrafficNational.OfficeID, tblTrafficNational.TrafficFormatID
HAVING (((tblTrafficNational.OfficeID)=7617));
This is the output I am getting but I want to see ALL formats and zeros where appropriate and there are 14 formats in the formats table not 7 that are shown below:
Query3OfficeIDTrafficFormatIDSumOfTrafficVolume1110063Delivered Walksorted Letters35199611110063Delivered Walksorted Flats8704101110063Delivered Sequenced Letters26599101110063Delivered Manual Letters1339561110063Delivered Packets17869101110063Delivered Special Delivery1910331110063Delivered Walksorted Packets1185504
The current tblTrafficFormat Table is:
tblTrafficFormatTrafficFormatIDFormatSummary FormatWeighting1Delivered Walksorted LettersLetters0.372Delivered Walksorted FlatsFlats0.533Delivered Sequenced LettersLetters0.314Delivered Manual LettersLetters0.535Delivered FlatsFlats0.766Delivered PacketsParcels3.077Delivered RM TrackedTracked7.668Delivered Special DeliverySD6.919Delivered Walksorted PacketsParcels1.9410LettersLetters
11FlatsFlats
12ParcelsParcels
13SDSD
14TrackedTracked
Please help.