Last post Aug 20, 2018 01:33 PM by limno
Aug 17, 2018 07:24 PM|vinod_praviram|LINK
I have idea about how to use rank function but what I am trying to achieve is that return all results from table but rank column should be null if score for row is 0 or negative.
Please tell me how to do that in SQL server 2012 and up?
Aug 17, 2018 07:45 PM|vinod_praviram|LINK
I tried this with case statement and it is returning desired result, but still need to confirm if that is good approach or there is any other better way to do it
(CASE WHEN Score > 0 THEN RANK() OVER (ORDER BY Score DESC) END) AS Position
This returns Position as Null for score 0 or negative, but still is there any better approach to do the task or above is fine and does not hurt performance of query?
Aug 20, 2018 08:52 AM|Deepak Panchal|LINK
I had made a test with your query and find that you had develop a proper query and you can certainly use it.
It is simple and i don't think there is other query simple like this which generates same output.
Aug 20, 2018 01:33 PM|limno|LINK
You can UNION ALL two query parts, one with ranking and the other without. This is just another option.