How to Replace String in SQL Server

How to Replace String in SQL Server table column with example?. For this Interview Question, We are going to use the below-shown data

String Functions Source Table 1

Replace String in SQL Server Example

In this replace string example, we will declare a string variable, and then we are going to replace a part of a string with a new string using the Replace Function.

-- SQL Server Query to Replace String
DECLARE @String_Expression varchar(50)
SET @String_Expression = 'Blog Provides Free Tutorial on SQL Server'

SELECT REPLACE (@String_Expression, 
                'Blog','Tutorial Gateway'
                ) AS 'SQL Server Replace'
How to Replace String in SQL Server 2

 This example shows how to replace a string in SELECT Statement. Here we are going to use the REPLACE Function while we are selecting data from the SQL Server table.

-- Replace Part of a String

SELECT [EmpID]
      ,[Full Name]
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Sales]
      ,[Email Adress]
      ,REPLACE([Email Adress], 'microsoft.com', 'tutorialgateway.org') AS [New EmailID]
  FROM [StringExample]
How to Replace String in SQL Server 3

Replace String in SQL Example 3

In this example, we will show you, How to replace string in UPDATE Statement. Here we are going to use the REPLACE Function in Update Statement.

-- Replace Part of a String

UPDATE [StringExample]
SET [Email Adress] = REPLACE([Email Adress], 'xyz.com', 'tutorialgateway.org')
How to Replace String in SQL Server 4