[英]XML from SQL column: Cannot call methods on nvarchar(max)
I have a sql query that is kicking back with an error on my column name saying 'cannot call methods on nvarchar(max). 我有一个sql查询,我的列名称错误,说'无法调用nvarchar(max)上的方法。
SELECT [LEARNER_COURSE_XML_TEST].[XML_EX].Query('declare namespace
x="http://tempuri.org/cmi.xsd";] (/x:cmi/x:core/x:time_taken)')
AS TimeTaken FROM [LEARNER_COURSE_XML_TEST]
The issue seems to centre around [XML_EX].value but I've tried a few things including changing the column type but i've finally come unstuck. 这个问题似乎以[XML_EX] .value为中心,但我尝试了一些事情,包括更改列类型,但我终于解开了。 Any pointers would be greatly appreciated.
任何指针都将非常感激。
Sounds like XML_EX
is of type nvarchar(max)
. 听起来像
XML_EX
的类型是nvarchar(max)
。 Try changing it to xml
. 尝试将其更改为
xml
。
You can also cast it in the query, like so: 您也可以在查询中强制转换它,如下所示:
select cast(lcxt.XML_EX as xml).query(...)
from learner_course_xml_test lcxt
Thanks for your responses guys. 感谢您的回复。 Turns out I was over complicating it as I don't have access to my namespace in the SQL table.
事实证明,由于我无权访问SQL表中的命名空间,因此我将其复杂化。 I did however start by changing my field type to XML so thanks Andomar.
然而,我开始将我的字段类型更改为XML,所以感谢Andomar。 My solution is below:
我的解决方案如下:
SELECT [LEARNER_COURSE_XML_TEST].[XML_EX].query('data(sco/cmicore/total_time)') AS TimeTaken FROM [LEARNER_COURSE_XML_TEST]
This extracts my total times as i'd hoped. 这就像我希望的那样提取我的总时间。 Thanks again.
再次感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.