TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Remove Special Chars in SQL Server
Ashish Srivastava
Apr 25
2016
Code
1.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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
select dbo.RemoveSpecialChars('
KishmishMêhrà')
How to Remove Special Chars
SQL Server