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)
精彩评论