I'm trying to replace just part of a string in our company database. The column in which I'm trying to update is MERGECODES (varchar(20),null). A typical value of this column would be something like 'M, GPE, T'.
I would like to replace every instance of T with KD but I'm getting the error below. It will allow me to change anything with the same number of characters or less, for example, it will allow me to replace T with K but not with KD. Any help would be greatly appreciated. Thanks guys!
Code:
UPDATE GoldMine.dbo.CONTACT1
SET MERGECODES = REPLACE(MERGECODES, 'T', 'KD')
ERROR:
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated. The statement has been terminated.
M, GPE, Tin avarchar(20)column, and you execute yourREPLACE- it just works without any problem. I'm thinking that you're probably updating too many rows and at least one of the rows yourUPDATEstatement hits contains too many characters in that column for theREPLACEto work. Try to use aWHERE id = 42or something clause - in order to update just a single row which you know is OK.