SQL REPLACE Function – Replace Text String

Last modified date:

REPLACE function is used to replace text string or its parts. It belongs to the category of string functions. I created big overview of T-SQL functions some time ago – you can find it here.

Syntax of the Function (3 arguments)

SELECT REPLACE(<Column with text in which we replace part of the text>, <The string we want to replace>, <New string>)
FROM dbo.Table

Function has 3 arguments:

  1. Text field in which the full or partial text replacement is performed
  2. Replaced string
  3. New string

Example of REPLACE Use

Create a variable of type text, where there will be dashes instead of spaces. Use REPLACE to replace the “-” character with a space ” ”

DECLARE @String AS VARCHAR(255) = 'Hi,-I'm-the-text';
SELECT REPLACE(@String,'-',' ') AS String_after_Replace;

sql replace function example

My name is Jan Zedníček and I work as a BI Developer at Kentico Software in Brno. Mostly you can see me there working in the office, but I also work partly as a freelancer. I have been working as a freelancer for many companies for more than 5 years, but Kentico is the matter of my heart. I used to work as a financial controller at companies like Aero Vodochody or Sberbank and I also used to be a bond program manager in Unicapital Investment group. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Category: SQL Functions

About Ing. Jan Zedníček - BI Developer, Finance controller

My name is Jan Zedníček and I work as a BI Developer at Kentico Software in Brno. Mostly you can see me there working in the office, but I also work partly as a freelancer. I have been working as a freelancer for many companies for more than 5 years, but Kentico is the matter of my heart. I used to work as a financial controller at companies like Aero Vodochody or Sberbank and I also used to be a bond program manager in Unicapital Investment group. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.