locked
need to write reverse to coalesce function RRS feed

  • Question

  • ID	code1	code2	code3	code4
    1	1	2	3	4
    2	1			
    3	1	2		
    4	1	2	3	
    

    How to write a select statement to get (its reverse coalesce function)

    ID error code

    1  4

    2  1

    3 2

    4   3

    Thursday, January 7, 2016 4:26 AM

Answers

  • If the missing values contain NULLs, then

    Select ID, Coalesce(code4, code3, code2, code1) As errorcode
    From YourTableName;

    Tom

    • Proposed as answer by Jingyang Li Thursday, January 7, 2016 4:57 AM
    • Marked as answer by MarkSubedi Thursday, January 7, 2016 5:29 AM
    Thursday, January 7, 2016 4:47 AM