Wednesday, December 14, 2011

Remove unwanted characters from a string

Sometime it is required to remove some part of string from a string and replace that with some other string. The replace function will help you solve the problem when you need to remove or replace string values from your specified queries results.

SELECT REPLACE ([ContactName], 'M','') AS ContactNamesNoM
FROM [Northwind].[dbo].[Customers]
This will return ContactNames where M in ContactNames will be replaced by white space.

The Syntax goes as:

REPLACE ( string_expression , string_pattern , string_replacement )

No comments:

Post a Comment