开发者

Sql Server: Isolating particular character

I'm running SQL Server 2008 R2. There are a number of records that have this funky � character in a particular colu开发者_StackOverflow社区mn. I'd like to isolate just those records and do a Replace() on them. The problem I'm having is when I run this query:

select * from stories where body like '%�%' and publishdate = 20110131

It will return stories where the � isn't in the body column. In each of those cases that I've checked, there is a normal ? character in the contents of the body column. So it seems that like '%�%' is matching both ? and �. Is there any Cast or Convert magic I can do to return records that actually have the � character?


Does the N prefix and a binary COLLATE clause do the job?

CREATE TABLE #stories
(
body nvarchar(100)
)

INSERT INTO #stories
SELECT N'normal ? char' UNION ALL SELECT N'funky � char' 

SELECT *
FROM #stories
WHERE body like '%�%'

SELECT *
FROM #stories
WHERE body like N'%�%' COLLATE Latin1_General_BIN2

DROP TABLE #stories
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜