久久久久久久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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 伊人成人在线视频 | 国产欧美久久久 | 日韩在线资源 | 国产专区在线播放 | 中文字幕黄色片 | 91久久精品日日躁夜夜躁欧美 | 欧美性生交 | 免费看黄色一级片 | 中文字幕一二区 | av免费看网站 | 精品一区二区在线播放 | 婷婷四房综合激情五月 | 一区二区毛片 | 国产午夜精品一区二区三区视频 | 亚洲午夜精品一区二区三区 | 免费av不卡 | 黄色片网站在线观看 | 色在线视频 | 免费观看一区二区三区 | 婷婷六月综合 | 天天综合影院 | 国产成人99久久亚洲综合精品 | 国产美女自拍视频 | 日韩精品一区在线观看 | 国产精品免费一区二区三区 | 国产一区精品在线观看 | 一区二区免费看 | av不卡在线播放 | 国产成人一区二区三区 | 午夜精品视频在线 | 色婷婷中文字幕 | 天天干天天干天天干 | 中文字幕精品视频 | 亚洲一区影院 | 狠狠做深爱婷婷综合一区 | 97视频免费在线观看 | 国产一区二区三区久久 | 天堂在线视频 | 亚洲人在线 | 一级黄色在线观看 | www.青青草 |