久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

與 NULL 合并

COALESCE with NULL(與 NULL 合并)
本文介紹了與 NULL 合并的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在一個視圖中發現了這個 SQL 片段,但我對它的用途感到相當困惑(為簡潔起見,實際 SQL 已縮短):

I found this snippet of SQL in a view and I am rather puzzled by it's purpose (actual SQL shortened for brevity):

SELECT
    COALESCE(b.Foo, NULL) AS Foo

FROM a
LEFT JOIN b ON b.aId=a.Id

我想不出與 null 合并的目的的單一原因,而不僅僅是這樣做:

I cannot think of a single reason of the purpose of coalescing with null instead of just doing this:

SELECT
    b.Foo AS Foo

FROM a
LEFT JOIN b ON b.aId=a.Id

或者至少不要顯式包含 NULL:

Or at the very least don't include the NULL explicitly:

SELECT
    COALESCE(b.Foo) AS Foo

FROM a
LEFT JOIN b ON b.aId=a.Id

我不知道這是誰創作的(所以我不能問),它是什么時候創作的,或者它是為哪個特定的 MS SQL Server 版本編寫的(當然是 2008 年之前的版本).

I don't know who authored this (so I cannot ask), when it was authored, or for what specific MS SQL Server version it was written for (pre-2008 for sure though).

是否有任何正當理由與 NULL 合并而不是直接選擇列? 我忍不住笑著把它寫成菜鳥錯誤,但這讓我想知道是否有一些我不知道的邊緣案例".

Is there any valid reason to coalesce with NULL instead of just selecting the column directly? I can't help but laugh and write it off as a rookie mistake but it makes me wonder if there is some "fringe case" that I don't know about.

推薦答案

你說得對 - 沒有理由使用:

You are right - there is no reason to use:

SELECT COALESCE(b.Foo, NULL)

...因為如果 b.foo 為 NULL,你不妨使用:

...because if b.foo is NULL, you might as well just use:

SELECT b.foo

...假設您知道該值是否為空.

...assuming that you want to know if the value is null.

這篇關于與 NULL 合并的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 亚洲第1页 | 伊人春色在线观看 | 成人日韩 | 日韩高清电影 | 成人毛片在线观看 | 盗摄精品av一区二区三区 | 国产高清久久久 | 超碰在线观看97 | 亚洲成av人影片在线观看 | 久久99精品久久久久久 | 颜色网站在线观看 | 亚洲精品成人av | 91精品久久久久久久久 | 国产精品久久久久久久久久了 | 日韩欧美国产精品一区二区 | 天天天操 | 精品久久电影 | 黄色av免费 | 欧美精品二区 | 成人黄色网址大全 | 国产精品区二区三区日本 | 欧美精品成人 | 91欧美精品成人综合在线观看 | 国产一级毛片精品完整视频版 | 久久精品亚洲精品 | 久久久久久免费毛片精品 | 亚洲欧美日韩电影 | 99精品国产一区二区三区 | 欧美国产日韩在线 | 粉嫩国产精品一区二区在线观看 | 亚洲精品在线观看网站 | 久草久草久草 | 国产日韩精品一区 | 天天艹日日干 | 色视频欧美| 一区二区国产精品 | 久久精品网 | 欧洲一区视频 | 中文字幕在线二区 | 一区二区在线视频 | 成人久久久久久久久 |