–Difference between STUFF and REPLACE IN SQL SERVER 2005

DECLARE @String AS VARCHAR(100)
SET @String = ‘Pawan’

–USE OF STUFF
SELECT STUFF ( @String , 2 , 3 , ‘X’ ) as ‘STUFFSTRING’
This will replace all the characters starting from 2 to length 3 to X
Output : pXn

SET @String = ‘Pawan’
–USE OF REPLACE
SELECT REPLACE ( @String , ‘a’ , ‘X’ ) as ‘REPLACESTRING’
This will replace all occurances of a with X
Output : pXwXn

Pawan Kumar
pawankkmr@hotmail.com

Advertisements