SQL Database Concepts Question:

Download Job Interview Questions and Answers PDF

Do you know what is REPLACE and STUFF function in SQL Server?

Basic SQL Server Interview Question
Basic SQL Server Interview Question

Answer:

STUFF: This function is used to replace the part of string with some another string.

Syntax:

STUFF (String1, Position, Length, String2)
String1 - String to be overwritten
Position - Starting Position for overwriting
Length - Length of replacement string
String2- String to overwrite

Example:
SELECT STUFF(‘Arpit',2,2,'mi')
Output: Amit

REPLACE: This function is used to replace all the occurrences of particular string by another string.

Syntax:
REPLACE(String1, String2, String3)

Example:
SELECT REPLACE(‘Arpit Jain’,’i’,’m’)
Output: Arpmt Jamn

If you want to replace the first occurrence of “I”, Replace wouldn't work, because it always replaces ALL occurrences of the string.

Download Basic SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
Do you know what is XPath?Explain what are the Authentication Modes in SQL Server?