Get the App
SLTechnology News&Howtos  ›  Servers  › 

Cloud computing learning roadmap materials, courseware, CASE search function grammar

Shulou Source: shulou.com Published: 2022-06-03 06:22:12 09月18日 Update

In this article, we will show you the syntax of CASE search function:

CASE

WHEN Boolean_expression THEN

Result_expression [... n] [

ELSE

Else_result_expression

END

Parameter description:

The Boolean expression evaluated by WHEN Boolean_expression when it uses the CASE search format. Boolean_expression is an arbitrarily valid Boolean expression. The result type returns the highest precedence rule type from the type collection of result_expressions and optional else_result_expression. For more information, see prioritization of data types.

CASE search function: return result value introduction:

Evaluates the Boolean_expression of each WHEN clause in the specified order. Returns the result_expression of the first Boolean_expression whose value is TRUE.

If there is no Boolean_expression with the value TRUE, SQL Server will return else_result_expression; when the ELSE clause is specified. If no ELSE clause is specified, the NULL value will be returned.

Introduction of CASE WHEN examples 1. Select statements with only simple case

Select

CASE good_type

WHEN'0' THEN

'Food category'

WHEN'1' THEN

'Beverages'

WHEN'2' THEN

'Commodity'

WHEN'3' THEN

'fresh fruits'

END AS good_type_now

Good_type,user_id,user_name

FROM

Express.t_main_order

+-+

| | good_type_now | good_type | user_id | user_name | |

+-+

| | Food category | 0 | 1 | tina | |

| | Food category | 0 | 2 | tige | |

| | Beverage category | 1 | 3 | five |

| | Commodity | 2 | 4 | wate |

| | fresh fruits | 3 | 5 | fiww | |

| | fresh fruits | 3 | 6 | www | |

| | fresh fruits | 3 | 7 | wfiw | |

+-+

Tags: Type fresh fruit search clause food food category function Boolean daily use commodity result expression order drink grammar highest effective lieutenant general example information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Shulou Technology Redmi NVidia