Friday , April 19 2024

Case When Statement in MySQL

The article contains information about CASE WHEN Statement in MySQL as an alternative to the if condition.

With the CASE statement used in MySQL as an alternative to the if function and if statement, desired commands can be executed according to a condition or value.

MYSQL Case When Statement

MySQL CASE WHEN statement is used to control situations where a value can take different values. It is also similar to the MySQL IF statement I mentioned in the MySQL IF Statement and MySQL IF() Function article.

Let’s perform the operations in article MySQL IF Statement and MySQL IF() Function using CASE WHEN.

Let’s use MySQL CASE WHEN statement according to the id column in the products table.

In the example, if the id value is 1, the result will be Computer, if it is 2, the result will be Mobile Devices, if it is 3, result will be Elektronics, and if it is another expression, it will return No Category.

Using CASE WHEN Statement in MySQL Stored Procedures

Lets execute the sp;
When the stored procedure is executed, the value Yusuf Sefa SEZER will be assigned to the @result .

The MySQL CASE WHEN statement also can be used as follows;

Have a good day.

Loading

About Yusuf SEZER

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories