SQL:ISNULL

來源:互聯網
上載者:User
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.99Cooking with Co business     11.95You Can Combat  business     2.99Straight Talk A business     19.99Silicon Valley  mod_cook     19.99The Gourmet Mic mod_cook     2.99The Psychology  UNDECIDED    0.00But Is It User  popular_comp 22.95Secrets of Sili popular_comp 20.00Net Etiquette   popular_comp 0.00Computer Phobic psychology   21.59Is Anger the En psychology   10.95Life Without Fe psychology   7.00Prolonged Data  psychology   19.99Emotional Secur psychology   7.99Onions, Leeks,  trad_cook    20.95Fifty Years in  trad_cook    11.95Sushi, Anyone?  trad_cook    14.99(18 row(s) affected)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.