- --case 範例 表達式只有一組
- SELECT
- CASE Cust_Name
- WHEN '張先生' THEN 1
- WHEN '曹先生' THEN 2
- ELSE 3
- END UseNo
- FROM Orders
- SELECT
- CASE SUBSTRING(emp_id, 2, 1)
- WHEN '1' THEN '男'
- WHEN '2' THEN '女'
- ELSE 'unknow'
- END Sex
- FROM employee
- --搜索式case子句 表達式有多組
- SELECT
- CASE
- WHEN cust_Name = '張先生' THEN 1
- WHEN cust_Name = '曹先生' THEN 2
- ELSE 3
- END USERNO
- , CASE
- WHEN CUST_NAME '%先生' THEN '男'
- ELSE '女'
- END SEX
- ,CASE
- WHEN QTY BETWEEN 0 AND 150 THEN 0.10
- WHEN QTY BETWEEN AND 300 THEN 0.15
- WHEN QTY > 300 THEN 0.2
- END DISCOUNT
- FROM ORDERS
沒有留言:
張貼留言