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

在 XML 變量中用 NULL 替換空字符串

Replace empty string with NULL in XML variable(在 XML 變量中用 NULL 替換空字符串)
本文介紹了在 XML 變量中用 NULL 替換空字符串的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我希望這個(gè)查詢返回 NULL 而不是空字符串.

I wish this query would return NULL instead of empty string.

declare @str varchar(max)='A,,C;D,E,F;X,Y,Z'; -- please notice missing B
declare @xmlstr XML
set @xmlstr = CAST(('<rows><row><col>' + REPLACE(REPLACE(@str,';','</col></row><row><col>'),',','</col><col>') + '</col></row></rows>') AS XML)

SELECT
     t.n.value('col[1]','nvarchar(max)') as Col1
    ,t.n.value('col[2]','nvarchar(max)') as Col2
    ,t.n.value('col[3]','nvarchar(max)') as Col3
FROM
    @xmlstr.nodes ('/rows/row') AS t(n)

這個(gè)例子來自https://stackoverflow.com/a/39752683/1903793

來自答案:SQL拆分字符串并獲得 NULL 值而不是空字符串 我知道它可以通過使用 NULLIF 函數(shù)輕松包裝來修復(fù):

From the answer: SQL split string and get NULL values instead of empty string I know it can be fixed by easy wrap with NULLIF function:

SELECT
     nullif(t.n.value('col[1]','nvarchar(max)'),'') as Col1
    ,nullif(t.n.value('col[2]','nvarchar(max)'),'') as Col2
    ,nullif(t.n.value('col[3]','nvarchar(max)'),'') as Col3

但是我想知道它是否可以通過直接使用 XML 變量 進(jìn)行操作來修復(fù),而不是之后進(jìn)行操作.

However I wonder if it might be alternatively fixed by manipulating with XML variable directly, not afterwards.

注意.我的問題遵循 SQL 拆分字符串并獲取 NULL 值而不是空字符串請(qǐng)不要將其標(biāo)記為欺騙,因?yàn)槲疫€沒有收到 XML 方法的答案.

Note. My question follows SQL split string and get NULL values instead of empty string Please do not mark it as dupe because I have not received answer for XML method.

推薦答案

此答案的功勞完全歸功于 Jeroen Mostert.詳情請(qǐng)看他的評(píng)論.

The credit for this answer is entirely to Jeroen Mostert. For details please see his comments.

declare @str varchar(max)='A,,C;D,E,F;X,Y,Z'; -- please notice missing B
declare @xmlstr XML
set @xmlstr = CAST(('<rows><row><col>' + REPLACE(REPLACE(@str,';','</col></row><row><col>'),',','</col><col>') + '</col></row></rows>') AS XML)

SELECT
     t.n.value('col[1]/text()[1]','nvarchar(max)') as Col1
    ,t.n.value('col[2]/text()[1]','nvarchar(max)') as Col2
    ,t.n.value('col[3]/text()[1]','nvarchar(max)') as Col3
FROM
    @xmlstr.nodes ('/rows/row') AS t(n)

這篇關(guān)于在 XML 變量中用 NULL 替換空字符串的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 成人av播放| 韩日在线 | 国产视频二区 | 欧美精品在线一区 | 成人污污视频 | 久久久国产一区二区三区 | 99免费视频 | 日韩欧美在 | 国产色婷婷精品综合在线手机播放 | 国产伦精品一区二区三区照片91 | av国产精品 | 亚洲日本欧美日韩高观看 | 久色一区| 成人免费在线视频 | 草草在线观看 | 福利片在线看 | 国产在线麻豆精品入口 | 国产视频线观看永久免费 | 欧美一级二级视频 | 久久久久久久久久久久久9999 | 国产精品美女久久久免费 | 日韩a在线 | 欧美久久久久久久久 | 亚洲v日韩v综合v精品v | 一区二区三区av | 国产伦精品一区二区三区在线 | 手机三级电影 | 亚洲一区二区三区在线播放 | 真人女人一级毛片免费播放 | 欧美一级欧美一级在线播放 | 欧美专区在线视频 | 国产精品福利在线 | 欧美精品久久久久 | 午夜影院毛片 | 日本天天操 | 国产日韩欧美在线一区 | 蜜桃在线一区二区三区 | av在线一区二区三区 | 日韩成人在线观看 | 亚洲经典一区 | 日韩图区 |