sqlserver有用函數
2024-07-21 02:07:44
供稿:網友
<!--#include file="./news/const.asp"-->isnull
使用指定的替換值替換 null。
語法
isnull ( check_expression , replacement_value )
參數
check_expression
將被檢查是否為 null的表達式。check_expression 可以是任何類型的。
replacement_value
在 check_expression 為 null時將返回的表達式。replacement_value 必須與 check_expresssion 具有相同的類型。
返回類型
返回與 check_expression 相同的類型。
注釋
如果 check_expression 不為 null,那么返回該表達式的值;否則返回 replacement_value。
示例a. 將 isnull 與 avg 一起使用
下面的示例查找所有書的平均價格,用值 $10.00 替換 titles 表的 price 列中的所有 null 條目。
use pubsgoselect avg(isnull(price, $10.00))from titlesgo
下面是結果集:
-------------------------- 14.24 (1 row(s) affected)
b. 使用 isnull
下面的示例為 titles 表中的所有書選擇書名、類型及價格。如果一個書名的價格是 null,那么在結果集中顯示的價格為 0.00。
use pubsgoselect substring(title, 1, 15) as title, type as type, isnull(price, 0.00) as pricefrom titlesgo
下面是結果集:
title type price --------------- ------------ -------------------------- the busy execut business 19.99 cooking with co business 11.95 you can combat business 2.99 straight talk a business 19.99 silicon valley mod_cook 19.99 the gourmet mic mod_cook 2.99 the psychology undecided 0.00 but is it user popular_comp 22.95 secrets of sili popular_comp 20.00 net etiquette popular_comp 0.00 computer phobic psychology 21.59 is anger the en psychology 10.95 life without fe psychology 7.00 prolonged data psychology 19.99 emotional secur psychology 7.99 onions, leeks, trad_cook 20.95 fifty years in trad_cook 11.95 sushi, anyone? trad_cook 14.99 (18 row(s) affected)