In my table I want to remove first 7 characters from the Title column.
I have a table like below and I want to remove the 'Copy of' prefix:
Title
---------------------
Copy ofthis is tile1
Copy ofthis is another tile2
I tried this:
Update MyTable SET Title=(SELECT RIGHT(Title,LEN(Title)- 7) AS Title)
WHERE Title LIKE 'Copy of%'
Any suggestions?
You don’t need a subquery for this, and generally you don’t need to check the length to figure out how long the output should be. Assuming this isn’t a
varchar(max), you could do:Or you could do:
You may also want to use
LTRIM()in case the value is'Copy of something'and you don’t want a leading space: