Articles → SQL SERVER → Stuff And Replace Functions In SQL Server
Stuff And Replace Functions In SQL Server
Software Requirement
Prerequisite Knowledge
- The basics of SQL Server objects such as tables, views, functions, etc.
- The difference between user-defined and system-defined functions
Replace Function
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
select
stuff('hello', 6, 2, 'how are you')
select
stuff('hello ', 6, 2, 'how are you')