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'
)
- The first parameter is the string to be searched.
- The second parameter is the string to be found.
- The third one is the string value which will be replaced.
Stuff Function
select
stuff(
'This is the original string', 6,
2, 'was'
)
- The first parameter is the string from which characters will be deleted and the new characters will be inserted.
- The second parameter specifies the starting position where the string will be inserted.
- The third parameter is the number of characters to delete from the start position.
- The fourth parameter is the new string that will be inserted at the start position.
More Examples For Stuff Function
select
stuff('hello', 6, 2, 'how are you')
select
stuff('hello ', 6, 2, 'how are you')