Suppose there is a table named "myTable" with three columns:
{**ID**(PK, int, not null),
**X**(PK, int, not null),
**Name**(nvarchar(256), not null)}.
Let {4, 1, account} be an entry in the table.
select * from myTable as t
where t.ID=4
AND t.X = 1
AND ( t.Name = N'' )
select * from myTable as t
where t.ID=4
AND t.X = 1
AND ( t.Name LIKE N'%%' )
The first query returns a record, but the second does not? Why?
Systems in which these problems occur:
* Windows XP - Professional - Version 2002 - SP3
Server sorting: Latin1_General_CI_AS
Version: 9.00.3073.00
Level: SP2
Edition: Developer Edition
Sever Collation: SQL_Latin1_General_CP1_CI_AS
Version: 9.00.3054.00
Level: SP2
Edition: Enterprise Edition
Results:
SELECT SERVERPROPERTY('SQLCharSetName')
iso_1
Using OSQL.exe
0x30043A043A04300443043D04420400000000000000000000000000000000
0x3F3F3F3F3F3F3F0000000000000000000000000000000000000000000000
0x253F3F3F3F3F3F3F25000000000000000000000000000000000000000000
SELECT CAST(name AS BINARY),
CAST(N'' AS BINARY),
CAST(N'%%' AS BINARY)
FROM myTable t
WHERE t.ID = 4
AND t.X = 1
CAST(name AS BINARY)
0x30043A043A04300443043D04420400000000000000000000000000000000
CAST(N'' AS BINARY)
0x3F3F3F3F3F3F3F0000000000000000000000000000000000000000000000
CAST(N'%%' AS BINARY)
0x253F3F3F3F3F3F3F25000000000000000000000000000000000000000000
source
share