带有二进制的 SQL WHERE 子句 [英] SQL WHERE clause with binary

查看:33
本文介绍了带有二进制的 SQL WHERE 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 varbinary(max) 列的 SQL Server 数据库表(即 create table 命令中的 Data VarBinary(max)).

I have a SQL Server database table with a varbinary(max) column (i.e. Data VarBinary(max) in a create table command).

是否可以在二进制数据中使用某种模式匹配来执行 where 子句?

Is it possible to do a where clause with some kind of pattern matching within the binary data?

例如,使用C#.NET的SqlCommand对象,我发现我可以做一个类似select * from TableName where Data = 0x4638763849838709 go的查询,其中的值是完整的数据列值.但我希望能够仅对部分数据进行模式匹配,例如 select * from TableName where Data = 0x%3876% go.

For example, using the C# .NET SqlCommand object, I found that I can do a query like select * from TableName where Data = 0x4638763849838709 go, where the value is the full data column value. But I want to be able to pattern match just parts of the data, like select * from TableName where Data = 0x%3876% go.

谢谢.

推荐答案

对于你在问题中给出的例子

For the example you have given in the question

WITH t(c) AS
(
SELECT CAST(0x4638763849838709 AS VARBINARY(MAX)) 
)
SELECT *
FROM t
WHERE CHARINDEX(0x3876,c) > 0

这篇关于带有二进制的 SQL WHERE 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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