Saturday, August 27, 2016

Remove special characters (-, _,) from string in SQL SERVER

In this article I am going to explain how to remove the special characters like coma (,), hyphen (-), underscore (_) from string using Sql server.



Implementation:

To remove the special characters from string I am using the REPLACE function of sql server.
I have created a table and insert some dummy record into it.


Remove special characters (-, _,) from string in SQL SERVER


I want to remove the.,_,- from student name and username. Here is the SQL  query to get student and username without special characters.

SELECT REPLACE(replace(StName,'.',' '),'_',' ') AS [Student Name],
replace(replace(replace(StUsername,'_',' '),'-',' '),'.',' ') as [username]
FROM Tb_Student

OUTPUT:


Remove special characters (-, _,) from string in SQL SERVER

No comments:

Post a Comment