Shaegi Shaegi - 21 days ago 9
SQL Question

Compare Dates in SQL in Case

For a task I need to update a table at 2 different cases once if the name is mobile business intelligence and if the date is beyond 1/1/2016. The first one is working fine but the second one isnt working.

Im using mysql on mariaDB with mysql workbench

update projekt
set budget = case projektname WHEN "Mobile Business Intelligence"
Then budget * 1.08
else budget
End
,budget = case beginndatum when < "2016-01-01"
then budget *1.04
else budget
End;


hope you can help me

Answer

CASE ... END syntax is documented:

CASE case_value
    WHEN when_value THEN statement_list
    [WHEN when_value THEN statement_list] ...
    [ELSE statement_list]
END CASE

Or:

CASE
    WHEN search_condition THEN statement_list
    [WHEN search_condition THEN statement_list] ...
    [ELSE statement_list]
END CASE

You obviously want to feed it with a search_condition rather than a when_value.

Comments