T-SQL、XQuery 无效列

T-SQL, XQuery Invalid Column(T-SQL、XQuery 无效列)
本文介绍了T-SQL、XQuery 无效列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习 XQUERY 并试图完成我认为非常简单的事情.这是我的 T-SQL 代码:

I'm just learning XQUERY and trying to accomplish what I thought would be very simple. Here's my T-SQL code:

DECLARE @XML xml
set @xml = '<resultsets><AppVersion>13.0</AppVersion></resultsets>'

-- Code below is wrong
select 
ResultSets.AppVersion.query('AppVersion').value('.', 'varchar(100)') as AppVersion
from @XML.nodes('/resultsets/AppVersion') ResultSets(AppVersion)

我不知道如何查询内部元素 appversion.我没有收到任何错误,但我无法在 appversion 内部元素中返回 13.0.有人可以帮忙吗?

I cannot figure out exactly how to query that inner element, appversion. I'm not getting any errors, but I'm unable to return that 13.0 within the appversion inner-element. Can someone please help?

推荐答案

如果您只想要一行,则无需使用 nodes.

If you only want one row as a result there is no need to use nodes.

DECLARE @XML xml
set @xml = '<resultsets><AppVersion>13.0</AppVersion></resultsets>'

select @XML.value('(/resultsets/AppVersion)[1]', 'varchar(100)') as AppVersion

这篇关于T-SQL、XQuery 无效列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)