使用 LIKE 或类似的完整搜索操作搜索 XML [英] Search XML with a LIKE or similar full search operation

查看:34
本文介绍了使用 LIKE 或类似的完整搜索操作搜索 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想搜索一个 XML 值列以查看 a 是否包含字符串.我不知道架构,我想知道字符串是否包含在任何地方.我不知道 XPATH 在这种情况下是否可以工作.

相当于

从表 t 中选择 s.Name, ts.ValueXML (nolock)在 t.key_Id = ts.key_Id 上加入 table2 ts (nolock)在 ts.key_Id=s.key_Id 上加入 table3 s (nolock)其中 s.Name 像 '%Lab%' 和 ts.ValueXML 像 '%PreviewDateRange%'

<块引用>

错误:参数数据类型 xml 对类似参数 1 无效功能.

相关ts表格列

ValueXml (XML(.), null)

我要搜索的项目应该是一个属性.因此,如果上述方法不可行,那么包含该属性的任何内容都是不错的选择.

解决方案

最简单(但绝对不是执行最快)的方法是在传递列之前将其强制转换为 nvarchar(max)喜欢:

cast(ValueXml as nvarchar(max)) like '%PreviewDateRange%'

I want to search an XML valued column to see if a contains a string. I don't know the schema, I want to know if the string is contained anywhere at all. I don't know if XPATH would work in this situation.

The equivalent of

Select s.Name, ts.ValueXML from table t (nolock) 
join table2 ts (nolock) on t.key_Id = ts.key_Id
join table3 s (nolock) on ts.key_Id=s.key_Id
where s.Name like '%Lab%' and ts.ValueXML  like '%PreviewDateRange%'

ERROR: Argument data type xml is invalid for argument 1 of like function.

relevant ts Table columns

ValueXml (XML(.), null)

The item I'm searching for should be an attribute. So if the above isn't possible, then anything containing that attribute would be a good alternative.

解决方案

The simplest (but definitely not the fastest to execute) way would be to cast your column to nvarchar(max) before passing it to like:

cast(ValueXml as nvarchar(max)) like '%PreviewDateRange%'

这篇关于使用 LIKE 或类似的完整搜索操作搜索 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆