如何在所有地方替换这个特殊字符
How to replace this special character at all the places
我尝试了以下方法,但结果不符合要求(我的意思是在 运行 替换查询后得到相同的结果)。如何替换所有只有特殊字符的地方?
这是查询。
select
REPLACE(description,'‚'COLLATE Latin1_General_BIN, N'‚')
from Zstandars_25Feb2015 where Colname = 56
结果:
.
....the form + = and = for cases in which , and
are all nonnegative ..........
您的描述字段的类型是什么?
如果它是 varchar,你应该不会遇到任何问题。我的测试中有 运行 你的查询 table 并且我没有收到这样的错误,它可能与你的排序规则有关,请删除排序规则并重试或将排序规则更改为其他内容。
-- Removes special characters from a string value.
-- All characters except 0-9, a-z and A-Z are removed and
-- the remaining characters are returned.
-- Author: Christian d'Heureuse, www.source-code.biz
create function dbo.RemoveSpecialChars (@s varchar(256)) returns varchar(256)
with schemabinding
begin
if @s is null
return null
declare @s2 varchar(256)
set @s2 = ''
declare @l int
set @l = len(@s)
declare @p int
set @p = 1
while @p <= @l begin
declare @c int
set @c = ascii(substring(@s, @p, 1))
if @c between 48 and 57 or @c between 65 and 90 or @c between 97 and 122
set @s2 = @s2 + char(@c)
set @p = @p + 1
end
if len(@s2) = 0
return null
return @s2
end
通过保留 N,我能够获取数据..
select
替换(描述,N'‚'COLLATE Latin1_General_BIN, N'‚')
来自 Zstandars_25Feb2015 其中 Colname = 56
感谢大家的帮助。
我尝试了以下方法,但结果不符合要求(我的意思是在 运行 替换查询后得到相同的结果)。如何替换所有只有特殊字符的地方? 这是查询。
select
REPLACE(description,'‚'COLLATE Latin1_General_BIN, N'‚')
from Zstandars_25Feb2015 where Colname = 56
结果: .
....the form + = and = for cases in which , and are all nonnegative ..........
您的描述字段的类型是什么? 如果它是 varchar,你应该不会遇到任何问题。我的测试中有 运行 你的查询 table 并且我没有收到这样的错误,它可能与你的排序规则有关,请删除排序规则并重试或将排序规则更改为其他内容。
-- Removes special characters from a string value.
-- All characters except 0-9, a-z and A-Z are removed and
-- the remaining characters are returned.
-- Author: Christian d'Heureuse, www.source-code.biz
create function dbo.RemoveSpecialChars (@s varchar(256)) returns varchar(256)
with schemabinding
begin
if @s is null
return null
declare @s2 varchar(256)
set @s2 = ''
declare @l int
set @l = len(@s)
declare @p int
set @p = 1
while @p <= @l begin
declare @c int
set @c = ascii(substring(@s, @p, 1))
if @c between 48 and 57 or @c between 65 and 90 or @c between 97 and 122
set @s2 = @s2 + char(@c)
set @p = @p + 1
end
if len(@s2) = 0
return null
return @s2
end
通过保留 N,我能够获取数据..
select 替换(描述,N'‚'COLLATE Latin1_General_BIN, N'‚') 来自 Zstandars_25Feb2015 其中 Colname = 56
感谢大家的帮助。