Articles → SQL SERVER → Stuff And Replace Functions In SQL Server
Stuff And Replace Functions In SQL Server
Software Requirement
Prerequisite Knowledge
- Basics about SQL server objects like table, views, functions etc.
- What is the difference between user defined and system defined functions?
Replace Function
Click to Enlarge
Syntax
SELECT
REPLACE(
'This is the original string', 'is',
'was'
)
- First parameter is the string to be searched
- Second parameter is the string to be found
- Third one is the string value which will be replaced
Stuff Function
select
stuff(
'This is the original string', 6,
2, 'was'
)
- First parameter is the string where the characters will be deleted and then inserted
- Second parameter is the starting position from where string will get inserted
- Third parameter is the number of characters to delete from start position
- Fourth parameter is the new string which will inserted at the start position
Click to Enlarge
select
stuff('hello', 6, 2, 'how are you')
select
stuff('hello ', 6, 2, 'how are you')