T SQL case 語法定義

2021-09-08 07:59:17 字數 1523 閱讀 3869

計算條件列表並返回多個可能結果表示式之一。

case 具有兩種格式:

兩種格式都支援可選的 else 引數。

語法

****** case function: case input_expression 

when when_expression then result_expression

[ ...n ]

[ else else_result_expression

] end

searched case function:

case

when boolean_expression then result_expression

[ ...n ]

[ else else_result_expression

] end

引數

input_expression

使用簡單 case 格式時所計算的表示式。input_expression 是任意有效的表示式

when

when_expression

使用簡單 case 格式時要與 input_expression 進行比較的簡單表示式。when_expression 是任意有效的表示式。input_expression 及每個 when_expression 的資料型別必須相同或必須是隱式轉換的資料型別。

n 佔位符,表明可以使用多個 when when_expression then result_expression 子句或多個 when boolean_expression then result_expression 子句。

then

result_expression

當 input_expression = when_expression 計算結果為 true,或者 boolean_expression 計算結果為 true 時返回的表示式。result expression 是任意有效的表示式

else

else_result_expression

比較運算計算結果不為 true 時返回的表示式。如果忽略此引數且比較運算計算結果不為 true,則 case 返回 null。else_result_expression 是任意有效的表示式。else_result_expression 及任何 result_expression 的資料型別必須相同或必須是隱式轉換的資料型別。

when

boolean_expression

使用 case 搜尋格式時所計算的布林表示式。boolean_expression 是任意有效的布林表示式。

結果型別

從 result_expressions 和可選 else_result_expression 的型別集中返回優先順序最高的型別。有關詳細資訊,請參閱 資料型別優先順序 (transact-sql)。

結果值簡單 case 函式:

case 搜尋函式:

SqlServer系列 語法定義符號解析

1 概述 2 具體內容 2.1 尖括號,用於分隔字串,字串為語法元素的名稱,sql語言的非終結符。2.2 定義操作符。用在生成規則中,分隔規則定義的元素和規則定義。被定義的元素位於操作符的左邊,規則定義位於操作符的右邊。2.3 方括號表示規則中的可選元素。方括號中的規則部分可以明確指定也可以省略。2...

Aspectj切入點語法定義

3 月,跳不動了?在使用spring框架配置aop的時候,不管是通過xml配置檔案還是註解的方式都需要定義pointcut 切入點 例如定義切入點表示式 execution com.sample.service.impl.execution 是最常用的切點函式,其語法如下所示 整個表示式可以分為五個...

C 重要的基礎語法定義

c 的基本語法定義 常量的定義方式 1,define 巨集常量 例如 define day 7 一般定義那些世界公認的數字定義 2 const 修飾的變數 例如 const int month 12 修飾自定義的引數 字串 1,c風格的字串 char str hello world 2 c 風格的字...