Hello.
I have been spoiled with the ease of Access, but have outgrown it and am using SQL Server Management Studio.
So, please excuse my ignorance on the topic of ignoring duplicates when counting or summing.
I have figured out how to eliminate duplicates by using Select Distinct for a detailed query. However, I am struggling when trying to add or count (the duplicates are being included in the totals).
Here is an abbreviated version of what I have thus far. It provides me the results grouped by the desired columns, but it is including the duplicates. What am I missing to eliminate duplicates in the totals? Thank you!
Select
Merchant Category = Case When cct.MerchantSICCode='5542' Then 'Automated Fuel Dispensers'
Else 'No MCC Assigned'
End,
ProductName=Case When cct.PricingStrategy IN ('XRGA','XRGB','XRGC') Then 'Signature'
Else 'Other Product'
End,
SalesTransactionCount=SUM(CASE When cct.TransactionCode='253' Then 1 Else 0 End),
SalesTransactionDollar=Sum(CASE When cct.TransactionCode='253' Then cct.TransactionAmount Else 0 End),
InterchangeGross=Sum(CASE When cct.TransactionCode='253' Then cct.Interchange Else 0 End)-1,
SalesReturnCount=SUM(CASE When cct.TransactionCode='255' Then 1 Else 0 End),
SalesReturnDollar=Sum(CASE When cct.TransactionCode='255' Then cct.TransactionAmount Else 0 End)-1,
InterchangeReverse=Sum(CASE When cct.TransactionCode='255' Then cct.Interchange Else 0 End)*-1
From
TransactionTable cct
Where
cct.TransactionDate Between '2015-01-01' AND '2016-12-31'
AND cct.MerchantSICCode Not In ('11','12','0','3','4','7')
Group By
Case When cct.MerchantSICCode='5542' Then 'Automated Fuel Dispensers'
Else 'No MCC Assigned'
End,
Case When cct.PricingStrategy IN ('XRGA','XRGB','XRGC') Then 'Signature'
Else 'Other Product'
End