I have a strange scenario where I need to return the right-most non-zero column in a table structured as follows:
GL Q1 Q2 Q3 Q4
1 100 0 0 0
2 100 900 250 0
3 600 100 0 1000
I am expecting the output to be:
GL Amount
1 100
2 250
3 1000
Is there anyway to accomplish this as a set-based approach without having to resort to a CASE statement or similar solution? Performance is going to be important here.
1 Answer