久久久久久久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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 精品久久99 | 色婷婷久久综合 | 在线观看视频中文字幕 | 亚洲 欧美 激情 另类 校园 | 久久精品二区亚洲w码 | 美女天天干天天操 | 久久99深爱久久99精品 | 免费成年网站 | 午夜电影网站 | 91精品国产91 | 亚洲一区二区久久 | 欧美一级免费看 | 在线观看国产 | 国产精品1区2区3区 一区中文字幕 | 我想看一级黄色毛片 | 久久精品91久久久久久再现 | 欧美日韩一二区 | 欧美中文字幕在线观看 | 欧美精品99 | 日韩精品免费一区二区在线观看 | 国产精彩视频 | 日韩在线观看 | 国产欧美日韩综合精品一区二区 | 91看国产 | 久久久国产精品入口麻豆 | 精久久| 国产精彩视频在线观看 | 伊人导航| 欧美看片 | 欧美精品第一页 | 欧美成人手机在线 | 中文一区二区视频 | 久久99精品久久久97夜夜嗨 | 亚洲精品成人在线 | 成人国产精品久久久 | 久久激情网 | 毛片99| 91久久精品一区二区二区 | 日韩三级在线 | 日韩在线免费视频 | 日日摸日日碰夜夜爽亚洲精品蜜乳 |