Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

for any repeated "contract_number" 1 row return where the "Qualification Percent" number is the highest.

In relation to previous question.
https://www.experts-exchange.com/questions/29134757/need-a-select-case-statement-that-will-add-2-fields-after-evaluating-a-calculation-in-the-case-statement.html?headerLink=workspace_answered_questions


SELECT [contract_number]
      ,[From_Dollar]
      ,[To_Dollar]
      ,[Base_Discount_Percent]
      ,[Start_Date]
      ,[End_Date]
      ,[Sum_Of_Sales_Current]
      ,CASE	
        WHEN ISNULL(base_Discount_Percent,0) = '' THEN 'no data'
        WHEN ISNULL(Sum_Of_Sales_Current, 0) < From_Dollar THEN 'BELOW RANGE'
		WHEN ISNULL(Sum_Of_Sales_Current, 0) > To_Dollar THEN 'ABOVE RANGE'
			ELSE 'BETWEEN RANGE' 
		END AS RANGE_SCORE,
CASE	WHEN Base_Discount_Percent IS NULL THEN ''--'NONE STATED'
		WHEN End_Date <= CAST(GETDATE() AS DATE) THEN 'OUT OF DATE'
		WHEN ISNULL(Sum_Of_Sales_Current, 0) < From_Dollar THEN '0'
			ELSE Convert(nvarchar(50),Base_Discount_Percent)  
		END AS  QUALIFICATION_PERCENT     
  FROM [program].[dbo].[TIER_CAT]

Open in new window


Instead of returning more than 1 record for THE field(contract_number) that has more than 1 to return.
I need only to return 1 ROW.

current return:
User generated image
desired return:
User generated image
So i need: for any repeated "contract_number" and a  has no "out of date" language in "Qualification Percent"
1 row return where the "Qualification Percent" number is the highest.

Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

omg !!  Beautiful ! Thanks very much !