Reputation:
I want to Replace a particular character on position 4 in sql Server , i know about replace or case when but my problem is that i just want to 4th position character replace ,
i am trying like
SELECT REPLACE(_NAME,0,1) AS exp FROM _EMPLOYEE
but it will not cheching 4th character
for example if _name
contain IMR002001
then it should be IMR012001
Upvotes: 5
Views: 272
Reputation: 1270873
Use stuff()
:
select stuff(_NAME, 4, 1, '@')
This replaces the substring starting at position 4 with length 1 with the string that is the fourth argument. The string can be longer or shorter than the string being replaced.
For your example:
select stuff(_NAME, 4, 1, '1')
Upvotes: 7