请解释此查询。我在谷歌上找不到这个,我想完整解释这个查询。 [英] Explain This Query Please. I Do Not Find About This On Google ,I Want Complete Explaination Of This Query .
本文介绍了请解释此查询。我在谷歌上找不到这个,我想完整解释这个查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT Stuff(
(SELECT N', ' + Name FROM Names FOR XML PATH(''),TYPE)
.value('text()[1]','nvarchar(max)'),1,2,N'')
stuff用于替换,删除子字符串
和for xml路径用于在单行中获取xml数据,但是多个节点
但是我无法理解这个中发生了什么
.value的( '文本()[1]', nvarchar(max)'),1,2,N'')
我的猜测是它以某种方式替换xml节点以获得逗号分隔的单行数据。 />
但是我很困惑,我想要理解这一切。
如果可能,请给我一个完整的解释。
非常感谢你。
stuff is used for replacing by removing a substring
and for xml path is used for getting xml data in a single row but multiple nodes
but i m unable to understand what going on in this
" .value('text()[1]','nvarchar(max)'),1,2,N'') "
my guess is it somehow replaces xml nodes to get comma separated single row data.
but i am confused and i want to understand it all.
please gimme a full explation if its possible.
thank you so much .
推荐答案
你的理解是正确的。这是为时间列表生成逗号单独的值。
当使用FOR XML时,这意味着用XML生成相关数据。
PATH更简单定义XML元素和属性的方法。
有关详细信息,请参阅 FOR XML路径(SQL Server)
所以当我们使用时字符串连接
SELECT N','+ Name,这意味着FOR XML将汇总所有值并将其视为单个节点。
以下代码
.value('text()[1]','nvarchar(max)')
将考虑数据类型为nvarchar(max)的text()[1]的节点值。您也可以使用nvarchar(4000)。
请考虑以下示例:
your understanding is correct. this is to generate Comma separate value for a list of time.
When FOR XML is used this mean generate the related data in XML.
PATH is a simpler way to define XML element and attributes.
for details please refer FOR XML Path(SQL Server)
So when we use use string concatenation
SELECT N', ' + Name , this means FOR XML will roll up all the values and consider it a single node.
Following code
".value('text()[1]','nvarchar(max)')"
will considered the node value which text()[1] of data type nvarchar(max). you can also use nvarchar(4000).
Consider the following example:
select
(Select ', ' + TABLE_NAME
from INFORMATION_SCHEMA.TABLES
FOR XML PATH(''),TYPE).value('text()[1]','nvarchar(4000)')
希望有所帮助。
Hope it help.
这篇关于请解释此查询。我在谷歌上找不到这个,我想完整解释这个查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文