Articles → SQL SERVER → Stuff And Replace Functions In SQL Server

Stuff And Replace Functions In SQL Server






Software Requirement





Prerequisite Knowledge




  1. Basics about SQL server objects like table, views, functions etc.
  2. What is the difference between user defined and system defined functions?

Replace Function






Picture showing how the replace function works in sql server





Syntax


SELECT 
  REPLACE(
    'This is the original string', 'is', 
    'was'
  )




  1. First parameter is the string to be searched
  2. Second parameter is the string to be found
  3. Third one is the string value which will be replaced

Stuff Function




select 
  stuff(
    'This is the original string', 6, 
    2, 'was'
  )




  1. First parameter is the string where the characters will be deleted and then inserted
  2. Second parameter is the starting position from where string will get inserted
  3. Third parameter is the number of characters to delete from start position
  4. Fourth parameter is the new string which will inserted at the start position
Picture showing how the stuff function works in SQL server






select 
  stuff('hello', 6, 2, 'how are you')




select 
  stuff('hello ', 6, 2, 'how are you')





Posted By  -  Karan Gupta
 
Posted On  -  Sunday, January 6, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250