Looking_for_answers Looking_for_answers - 8 days ago 5
SQL Question

I want to find the 'N/A' value and update it with the next value

I have a table wherein alot of values are 'N/A' there. i want to update it with the next non 'N/A' value.

my table:

col1 || column2 || Column3


N/A || ACT0001 || ACT0002


ACT0004 || N/A || ABT0003


N/A || N/A || AND0009


output:

Column4

ACT001

ABT003

AND009


Thank you in advance

Answer

Not sure I understood you, maybe something like that?

UPDATE YourTable t
SET t.col4 = CASE WHEN t.col1 = 'N/A' THEN
                                           CASE WHEN t.col2 <> 'N/A' THEN t.col2
                                                ELSE t.col3
                                           END
                  WHEN t.col2 = 'N/A' THEN t.col3 
             END