I am working with SQL server 2008, and facing problem about character replacement.
If I use
SELECT REPLACE(MYWORD,0,1) FROM MYTABLE
It is replacing all 0 into 1, I just want to replace Last character Like MYWORD = "ERMN0"
so it will be MYWORD = "ERMN1"
using STUFF
, which, IMO, ends up being most readable:
DECLARE @MyWORD VARCHAR(20) = 'ABCDEF123'
SELECT STUFF(@MyWORD, LEN(@MyWORD), 1, '2')
output:
ABCDEF122
Try this.
SELECT LEFT('ERMN0', Len('ERMN0')-1)
+ Replace(RIGHT('ERMN0', 1), 0, 1)
OUTPUT : ERMN1
In your case
SELECT LEFT(MYWORD, Len(MYWORD)-1)
+ Replace(RIGHT(MYWORD, 1), 0, 1) as [REPLACED] FROM MYTABLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With