How to replace string in SQL Server?
Here i will give an example how to replace a substring in a string in SQL Server.
For example you want to change domain in Employee email addresses in 'EmployeeDetails' table.
In the below example i am replacing EmailId from "@gmail.com" to "studentboxoffice.in" in 'EmployeeDetails' Table .
Declare @txt1 varchar(50) set @txt1 = 'firstname.lastname@example.org' /* Here i am replacing @gmail.com to @studentboxoffice.in */ set @txt1 = REPLACE(@txt1, '@gmail.com', '@studentboxoffice.in') select @txt1
Output: -------------- email@example.com
You can also update employee emailid in 'EmployeeDetails' table.
-- before update EmailID = 'firstname.lastname@example.org'
update EmployeeDetals set EmailID = REPLACE(EmailID, '@gmail.com', '@studentboxoffice.in') where EmployeeCode = 3151
-- After updating EmailID = 'email@example.com'
CreatedAug 20, 2013
UpdatedOct 03, 2020
Different types of variables in SQL Server
What is Cross Join in SQL Server
How delete record from parent table when there is Foreign Key relation in SQL Server
What is the differences between CHAR, NCHAR, VARCHAR and NVARCHAR in SQL Server?
How to add or remove a column from a table in SQL Server?
How to insert values into Identity Column in SQL Server?
How to get a fixed-length value in SQL Server?
What is Left Join (or) Left Outer Join in SQL Server?
How to get current week dates in SQL Server?
What are the different types of Date formats in SQL Server?