Skip to content
Advertisement

Remove/update line breaks from string in sql columns

I have done OCR on some books’ titles which, for some reason, added line breaks too. Now I want to bulk remove/update them all permanently, not in select view. These are the queries I am running

SELECT Replace(BOOKTITLE, Char(13) + Char(10), ''), 
       Len(Replace(BOOKTITLE, Char(13) + Char(10), '')) 
FROM   BOOKTABLE; 

SELECT BOOKTITLE AS [(No column name)], 
       Len(BOOKTITLE) 
FROM   BOOKTABLE; 

which yield following results

enter image description here

How can I get it done?

Advertisement

Answer

If line breaks are always at the end of BOOKTITLE then you can do this update

UPDATE BOOKTABLE SET BOOKTITLE = LEFT(BOOKTITLE, LEN(BOOKTITLE) - 2)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement