开发者

Sql Server: Isolating particular character

开发者 https://www.devze.com 2023-03-02 15:36 出处:网络
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(

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

精彩评论

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