- -- charindex 函數
- SELECT *
- ,CHARINDEX(season, '冬天春天夏天秋天') pos
- ,ROW_NUMBER() OVER(ORDER BY season) "ex ante"
- FROM
- (
- SELECT '春天' season
- UNION
- SELECT '夏天'
- UNION
- SELECT '秋天'
- UNION
- SELECT '冬天'
- )a
- ORDER BY
- CHARINDEX(a.season, '春天夏天秋天冬天')
- --NULLIF 函數 (EXP1, EXP2) 與EXP2比較,相同回傳NULL, 否則回傳EXP1
- SELECT 100*1/ NULLIF(VAL, 0) "RATIO"
- ,CASE WHEN VAL=0 THEN NULL
- ELSE CAST( 100.0*1/VAL AS INT) END "ratio2"
- FROM
- (
- SELECT 0 val
- UNION ALL
- SELECT 2 val
- )a
沒有留言:
張貼留言