带有二进制的 SQL WHERE 子句 [英] SQL WHERE clause with binary
问题描述
我有一个带有 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屋!