How to replace nth character in sql server

Use stuff():

select stuff(abc, 0, 1, 'a')

It is documented here.


use stuff The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

select STUFF(ABC, starting_index, 1, 'X') from XXX

"Here your int position to replace" is the position no just replace with any int no and that position will be replaced Note : (Thanks to pcnate for suggestion) starting_index is your int position to replace.


You use STUFF for this:

SELECT STUFF(ABC, 5, 1, '1')
FROM XXX

This would replace the 5th character with a 1.


You're looking for STUFF:

select STUFF(ABC, @n, 1, 'X') from XXX

This would replace the @nth character with an X.

Technically it seeks into the original string at column ABC starting at position @n, deletes 1 character, then inserts the string 'X' at that position.