Hi,
I need help with the grouping of results I'm receiving, so that the resultset is reduced and like Store Chains are consolidated along with their totals added together, but I'm having problems trying to get this.
My current results are:
Store Chain Amt
Walgreens Drug Store #0612 54118
Walgreens Drug Store #0613 47460
Walgreens Drug Store #0614 419134
Walgreens Drug Store #0619 12430
Wegmans Pharmacy #118 305274
Wegmans Pharmacy #119 452248
Wegmans Pharmacy #120 182486
Wegmans Pharamcy #147 97201
WEIS PHARMACY 122 724408
WEIS PHARMACY 14 146974
WEIS PHARMACY 143 631561
WEIS PHARMACY 166 419134
WEIS PHARMACY 222 631561
Weldon Pharmacy 79773
WellPartner 10707
What I need is the following results:
Store Chain Amt
<Independent> 90480
Walgreens Drug Store 533142
WEGMANS 1037209
WEIS 2553638
Here is the SQL I currently have:
Code:
DECLARE @StartDate Datetime, @EndDate Datetime
SET @StartDate = '2011-03-01'
SET @EndDate = '2011-03-01'
SELECT
c.Pharmacy_Name AS Chain,
COUNT(s.Unique_ID) AS [# Paid]
FROM
Sales s
INNER JOIN Chains c
ON s.Chain_ID = c.Unique_ID
WHERE
s.TimeStamp BETWEEN @StartDate + '00:00:00.000' AND @EndDate + '23:59:59.999'
GROUP BY
c.Pharmacy_Name
ORDER BY
c.Pharmacy_Name
How can I get this query to give the results I need above? Can someone please help?