Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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 | |

+-+

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report