SQL 列中的 XML:无法调用 nvarchar(max) 上的方法 [英] XML from SQL column: Cannot call methods on nvarchar(max)
问题描述
我有一个 sql 查询,在我的列名上出现错误,提示无法调用 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).
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]
问题似乎集中在 [XML_EX].value 上,但我尝试了一些事情,包括更改列类型,但我终于摆脱了困境.任何指针将不胜感激.
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. Any pointers would be greatly appreciated.
推荐答案
感谢各位的回复.结果我把它复杂化了,因为我无权访问 SQL 表中的命名空间.然而,我确实首先将我的字段类型更改为 XML,所以感谢 Andomar.我的解决方案如下:
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. I did however start by changing my field type to XML so thanks 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.
这篇关于SQL 列中的 XML:无法调用 nvarchar(max) 上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!