SQL大小写表达式语法? [英] SQL Case Expression Syntax?

查看:98
本文介绍了SQL大小写表达式语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是SQL Case表达式的完整和正确的语法?

What is the complete and correct syntax for the SQL Case expression?

推荐答案

完整语法取决于您使用的数据库引擎:

The complete syntax depends on the database engine you're working with:

对于SQL Server:

For SQL Server:

CASE case-expression
    WHEN when-expression-1 THEN value-1
  [ WHEN when-expression-n THEN value-n ... ]
  [ ELSE else-value ]
END

或:

CASE
    WHEN boolean-when-expression-1 THEN value-1
  [ WHEN boolean-when-expression-n THEN value-n ... ]
  [ ELSE else-value ]
END

表达式等:

case-expression    - something that produces a value
when-expression-x  - something that is compared against the case-expression
value-1            - the result of the CASE statement if:
                         the when-expression == case-expression
                      OR the boolean-when-expression == TRUE
boolean-when-exp.. - something that produces a TRUE/FALSE answer

链接:案例(Transact-SQL)

还要注意,WHEN语句的顺序很重要.您可以轻松地编写多个重叠的WHEN子句,并使用第一个匹配的子句.

Also note that the ordering of the WHEN statements is important. You can easily write multiple WHEN clauses that overlap, and the first one that matches is used.

注意:如果未指定ELSE子句,并且找不到匹配的WHEN条件,则CASE表达式的值为 NULL .

Note: If no ELSE clause is specified, and no matching WHEN-condition is found, the value of the CASE expression will be NULL.

这篇关于SQL大小写表达式语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆