Hi Everyone,
Been a few years since I had to post anything here so I'm glad to be back.
I've been asked to do a report to show vouchers that have been issued and presented for July (this year and last year).
I have done this SQL:
SELECT tblOutlet.OL_NAME, Format([VI_TRANSACTION_DATE_TIME],"mmmm yyyy") AS MONTH_NAME, Count(tmpVoucherIssues.VI_ID) AS ISSUED, Sum(IIf(Nz([VH_ID])>0,1,0)) AS PRESENTED
FROM (tmpVoucherIssues LEFT JOIN tblVoucherHeader ON tmpVoucherIssues.VI_FORM_NUMBER = tblVoucherHeader.VH_NUMBER) INNER JOIN tblOutlet ON tmpVoucherIssues.VI_OL_ID = tblOutlet.OL_ID
GROUP BY tblOutlet.OL_NAME, Format([VI_TRANSACTION_DATE_TIME],"mmmm yyyy");
Returned Data:
Retailer 1 July 2012 269 202
Retailer 1 July 2013 285 173
Retailer 2 July 2012 170 112
Retailer 2 July 2013 204 124
Retailer 3 July 2012 201 151
Retailer 3 July 2013 228 143
Retailer 4 July 2013 584 372
Retailer 5 July 2013 949 565
Retailer 6 July 2012 132 86
Retailer 6 July 2013 221 141
In July 2012 Reteiler 4 and 5 did not produce any results, but I want the results to show as:
Retailer 4 July 2012 0 0
Retailer 5 July 2012 0 0
Please can you help me to re-write the sql?
Thanks in advance.
Darren
Please note I'm using mySQL as my database.