UPDATE CASE IN MYSQL

Below is the code which demonstrates the usage of CASE statement for UPDATE in MYSQL

UPDATE employee SET
empgrade=
  CASE 
    WHEN UPPER(TRIM(`COL1`))=UPPER('A') THEN A1
    WHEN UPPER(TRIM(`COL1`))=UPPER('B') THEN B1
    WHEN UPPER(TRIM(`COL1`))=UPPER('C') THEN C1
    WHEN UPPER(TRIM(`COL1`))=UPPER('D') THEN D1
    WHEN UPPER(TRIM(`COL1`))=UPPER('E') THEN E1
    WHEN UPPER(TRIM(`COL1`))=UPPER('F') THEN F1
    WHEN UPPER(TRIM(`COL1`))=UPPER('G') THEN G1
    WHEN UPPER(TRIM(`COL1`))=UPPER('H') THEN H1
    WHEN UPPER(TRIM(`COL1`))=UPPER('I') THEN I1
    WHEN UPPER(TRIM(`COL1`))=UPPER('J') THEN J1
    WHEN UPPER(TRIM(`COL1`))=UPPER('K') THEN K1
  END
 WHERE empdept=3;

No comments:

Post a Comment