There are more ways ...
1. You can put the actual values in a variable and test them for the equality in the next iteration
2. You can write another query that tells you number of occurences for every Part No + Case No and use it for the cursor
3. As 2. and to join it with the original query