troubleshooting Question

How to remove all special characters except commas?

Avatar of Storminator16
Storminator16 asked on
Microsoft SQL ServerSQL
1 Comment1 Solution6773 ViewsLast Modified:
Per the question, how would I do this in regards to the script below?  Thanks in advance.
declare @string varchar(2000) 
declare @newstring varchar(2000)
declare @num int
declare @code int
select @string = '!@#,$%^,&*(,)'
select @newstring = ''
select @num = 1
 
while @num < len(@string)+1
begin
	set @code = Ascii(SubString(@String, @Num, 1))
	--- ascii: 48-57 (numbers 0-9)
	--- ascii: 65-90 (uppercase letters A-Z)
	--- ascii: 97-122 (lowercase letters a-z)
	If (@code between 48 and 57) or (@code between 65 and 90) or (@code between 97 and 122)
	begin
		set @newstring = @newstring + Substring(@string, @num, 1)
	end
	set @num = @num + 1
end
 
select @newstring
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros