-1

In the query below only first Two cases are working why

UPDATE `FundCategory` SET `fundCategoryValue` = 
    CASE 
    WHEN `fundCategoryId` = '7' THEN fundCategoryValue + 700 
    WHEN `fundCategoryId` = '5' THEN fundCategoryValue - 700 
    WHEN `fundCategoryId` = '5' THEN fundCategoryValue + 700 
    WHEN `fundCategoryId` = '7' THEN fundCategoryValue - 700 

    ELSE `fundCategoryValue` 
    END
    WHERE `fundCategoryId` IN('7','5','5','7')
Shahneel Ahmed
  • 163
  • 3
  • 18
  • Possible duplicate of [MySQL update CASE WHEN/THEN/ELSE](http://stackoverflow.com/questions/12754470/mysql-update-case-when-then-else) – B001ᛦ Feb 01 '17 at 13:45
  • because 3 and 4 are identical to 1 and 2??? – e4c5 Feb 01 '17 at 13:46
  • it will not go for next two condition WHEN `fundCategoryId` = '5' THEN fundCategoryValue + 700 WHEN `fundCategoryId` = '7' THEN fundCategoryValue - 700 . it always fulfill first two condition – krishn Patel Feb 01 '17 at 13:46

2 Answers2

2

The conditions repeate after the first two... and the case statement stops when it found a working condition... so the last two can not work.

Jan Zeiseweis
  • 3,718
  • 2
  • 17
  • 24
0

You have the same condition repeated twice:

WHEN `fundCategoryId` = '7' THEN fundCategoryValue + 700 
WHEN `fundCategoryId` = '5' THEN fundCategoryValue - 700 
WHEN `fundCategoryId` = '5' THEN fundCategoryValue + 700 
WHEN `fundCategoryId` = '7' THEN fundCategoryValue - 700 
Krishnakumar
  • 725
  • 1
  • 6
  • 11