SQL Case Statement
Hi , I have multiple records for an employee in a table. I want to dispplay a 1 for the max sales value and a 0 if not max for each employee. Can you tell me how to do this using a case statement or some other way. Thanks
May 15th, 2012 9:44am

The easiest way would be to use RANK OVER Partition to add a column in your data listing the rank of the sales value in desc order. Then you could use a case statement to check for rankcolumn = 1Chuck
Free Windows Admin Tool Kit Click here and download it now
May 15th, 2012 10:06am

Something like this: SELECT employeeID , SalesValue , MaxSalesValue = CASE WHEN RANK() OVER (PARTITION BY EmployeeID ORDER BY SalesValue DESC) = 1 THEN 1 ELSE 0 END FROM YourTable Chuck
May 15th, 2012 10:11am

Thank You for the help!!!
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2012 2:16am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics