Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Totals - get a zero for no data

Status
Not open for further replies.

jpkeller55

Technical User
Apr 11, 2003
131
US
I have the query listed below in red that counts ShipperID's and DivID's from data in a table and assigns the field name DataName. Does anybody know how I can assign a zero count if a particular ShipperID or DivID is not entered on the table? For example if the data looks like this:

ShipDate ShipperID DivID
9/14/05 FedEx AT
9/14/05 FedEx NF
9/14/05 Courier AT

And I want the below query to produce this:

ShipDate DataName CountTotals
9/14/05 FedEx 2
9/14/05 Courier 1
9/14/05 Taxi 0
9/14/05 AT 2
9/14/05 NF 1
9/14/05 HS 0

SELECT ShipDate, ShipperID As DataName, Count(ShipperID) As CountTotals From ShipDetailTable GROUP BY ShipDate, ShipperID
UNION SELECT ShipDate, DivID, Count(DivID) From ShipDetailTable GROUP BY ShipDate, DivID;


Any thoughts? THanks!
 
do you have a table that lists all the possible shipperIDs?
 
Yes...I have a table called SHIPPERS and also a table for DIVISIONS

Thanks
 
Sorry, the tables are named: ShipperTable and DivisionTable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top