开发者

WHERE Clause Requires Like When Equals Should Work

I have a query that I think should look like this:

select *
from Requesters
where CITIZEN_STATUS = 'OS-IE ';

The field CITIZEN_STATUS, whose data type is varchar(15), has a trailing space for this particular value. I have pasted it into Notepad++ and looked at it with a hex editor, and the final space is indeed 0x20.

For the query to work, I have to write it like this:

select *
from Requesters
where CITIZEN_STATUS like 'OS-IE%';

So, obviously, I have a workaround and the question is not urgent. But I 开发者_高级运维would really like to know why the first query fails to do what I expect. Does anyone have any ideas?

I should mention I am using SQL Server 2005 and can provide more information about the configuration if needed.


In MySQL 5, this query works. However, it does not distinguish on trailing whitespace. The query matches 'OS-IE ' as well as 'OS-IE'. In SQL Server 2005 you can use a regular expression that defines the end of a line. The correct character for this is the dollar sign '$' to indicate that you do want the space. See http://msdn.microsoft.com/en-us/magazine/cc163473.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜