我有一个带有 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 子句
发布评论