Search code examples
sql-server-2017

Using "Rank()" Function I need to update the Rank based on the TotalMark but marks should not be Null


Using Rank() Function Updating the Rank to TotalMarks in null

Using Rank() Function Updating the Rank to TotalMarks is not null

I'm updating the Rank based on the TotalMarks. If the TotalMarks is not null the rank is updating but (here the issue is) it should not allow to update the Rank if the TotalMarks is null.

How to resolve this?


Solution

  • Just use a CASE expression

    CASE WHEN TotalMarks IS NOT NULL THEN RANK() OVER (ORDER BY TotalMarks DESC) END