开发者

C# and SQL LIKE condition: '%' works as single-character wildcard

I have query like that 开发者_C百科in my DataSet (database is located in .mdf file):

SELECT *
FROM TableName
WHERE SomeField LIKE @Param

Table TableName contains record Значение in SomeField field.

When @Param is Значени% it's works perfectly, but when @Param is Значен% or Значе%, it's returns 0 rows. Значе%%% also works.

Why '%' works as single-character wildcard?


Your problem is that you should be using @param of NVARCHAR, not NCHAR

declare @Param nchar(255)
set @Param = N'Значе%'

This is really

N'Значе%             ...' (many more spaces)

So it won't match your data, which is

N'Значение             ...' (padded with spaces)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜