SQL 查詢語句 IIF()處理條件判斷

2021-08-10 22:35:02 字數 875 閱讀 5672

語法

iif(expr,truepart,falsepart)

例子: ‍select iif(選擇=-1,"",金額) as 新金額 from 表1;已經測試通過! 在access中,"-1"表示"是","0"表示"否"!

iif 返回由邏輯測試確定的兩個數值或字串值之一。

語法 數字 iif(logical expression, numeric expression1, numeric expression2)

如果 logical expression 取值為 true,則此函式返回 numeric expression1,否則,返回 numeric expression2。

字串 iif(logical expression, string expression1, string expression2)

如果 logical expression 取值為 true,則此函式返回 string expression1,否則,返回 string expression2。

注釋 只有當 logical expression 的值為零時,才認為該表示式是 false。任何其它值都被解釋為 true。 不推薦用 iif 函式基於搜尋條件建立成員的集合。請改用 filter 函式根據邏輯表示式評估指定集合中的每個成員,然後返回成員的子集合。

示例 數字 如果 measures.currentmember 是空單元,則下面的示例返回 0,否則返回 1: iif(isempty(measures.currentmember), 0, 1)

字串 如果 measures.currentmember 是空單元,則下面的字串返回字串 "yes",否則返回字串 "no": iif(isempty(measures.currentmember), "yes", "no")

SQL常用條件查詢語句

select from table1 where 工資 2500 and 工資 3000 同上 select 姓名 from table1 where 性別 0 and 工資 4000 select from table1 where not 工資 3200 select from table1 o...

SQL語句多條件查詢

sql多條件查詢中如果有and和or,and的優先順序高於or,如果不加括號會先執行and,然後再執行or 資料表 一 查詢時先且查詢,則先and條件查詢,查詢結果與or後面的條件進行或查詢 sql語句 select from ceshi where name a and age 10 or 1查詢...

條件複雜的sql語句查詢

有三張表 分別為 會員表 member 銷售表 sale 退貨表 regoods 會員表有字段 memberid 會員id,主鍵 credits 積分 銷售表有字段 memberid 會員id 外來鍵 購買金額 mnaccount 退貨表中有字段memberid 會員id 外來鍵 退貨金額 rmna...