The query returns MOSTLY correct data, but in two rows, there's duplicate information in most of the columns, but one of the columns is pulling the wrong info.
I've tried to upload a copy of the results, but was unable to. If you would like, I will Message you a copy of the results in excel format.
Any suggestions you have, would be greatly appreciated.
Here is my query:
(more comments below)
SELECT DISTINCT FL.[Event Profile Contact], FL.[Rebate ID], FL.[Promo Name], CONVERT(VARCHAR (10), FL.[Promo Start Date], 111) AS 'Start Date', CONVERT(VARCHAR (10), FL.[Promo End Date], 111) AS 'End Date', CONVERT(VARCHAR (10), FL.[Promo Final RDMT Date], 111) AS 'Final Date', COUNT(FL.[Rebate ID]) AS 'FY # Of RBTs', SUM(FL.[Total Rebate Amount])/(COUNT(FL.[Rebate ID])) AS 'FY AVG $ PER RBT', SUM(FL.[Total Rebate Amount]) AS 'FY TTL DOLLARS', CASE WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] IS NULL THEN FL.[Budget Amount] WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] = FL.[Budget Amount] THEN FL.[Budget Amount] ELSE FL.[BUDGET FY'2012 or Accrued from FY'2010] END AS 'Budget Amount', CASE WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] IS NULL THEN ISNULL(FL.[Budget Amount], 0.00) - SUM(FL.[Total Rebate Amount]) WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] = FL.[Budget Amount] THEN ISNULL(FL.[Budget Amount], 0.00) - SUM(FL.[Total Rebate Amount]) ELSE ISNULL(FL.[BUDGET FY'2012 or Accrued from FY'2010], 0.00) - SUM(FL.[Total Rebate Amount]) END AS 'Variance TO Budget', CASE WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] IS NULL THEN FL.[Budget Amount] WHEN FL.[BUDGET FY'2012 or Accrued from FY'2010] = FL.[Budget Amount] THEN FL.[Budget Amount] ELSE FL.[BUDGET FY'2012 or Accrued from FY'2010] END AS 'Ending Budget FY2011' FROM vw_FlashReport_Part1_Select FL WHERE FL.[Counter Set Date] BETWEEN '2011-07-01' AND '2012-02-01' --fiscal ytd Group By FL.[Event Profile Contact], FL.[Rebate ID], FL.[Promo Name], FL.[BUDGET FY'2012 or Accrued from FY'2010], FL.[Budget Amount], FL.[Promo Start Date], FL.[Promo End Date], FL.[Promo Final RDMT Date]
The reason for the CASE WHEN is to say, that if there is any $value in the [BUDGET FY'2012 or Accrued from FY'2010] field, to use it, otherwise use the [Budget Amount] field. (and yes, in some cases, both fields have the same value)
Thanks in advance.

New Topic/Question
Reply



MultiQuote





|