Hi All,
I have table which has data with lot of CR LF, Is it possible to update that string as empty.
Yes. The following will do the trick for LfCr, CrLf, Cr, and Lf... Just replace the table name and the column name with your actual table and column names.
UPDATE dbo.YourTableNameHere
SET YourColumNameHere = REPLACE(REPLACE(YourColumNameHere,CHAR(13),''),CHAR(10),'')
WHERE YourColumNameHere LIKE CONCAT('%[',CHAR(13),',',CHAR(10),']%')
;
It will only replace the Cr and Lf characters with empty strings. Any other characters will come out unscathed. You'll need to play a bit if you want a space for one or the other character or a single space for both but I'm sure you get the idea here.
Please see the following references for more information on the world of ASCII character numbers...
https://learn.microsoft.com/en-us/sql/t-sql/functions/char-transact-sql
https://www.lookuptables.com/text/ascii-table
--Jeff Moden
Change is inevitable... Change for the better is not.
January 9, 2023 at 9:58 am
but why do that update? if the data is there it likely has a good reason for it and should not be changed on a whim. (specially not if it is only so you can view it on notepad!!!)
January 9, 2023 at 4:00 pm
CR LF is breaking my data load into mysql, I have updated CR LF as space ' ' and load is working good.
January 9, 2023 at 4:24 pm
CR LF is breaking my data load into mysql, I have updated CR LF as space ' ' and load is working good.
To Frederico's point, it may be that would be that the "data load" in MySQL is what actually needs to be fixed. On the other hand, any kind of formatting being stored in the DATA in a DATA base is usually a bad idea, IMHO. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
January 9, 2023 at 5:05 pm
CR LF is breaking my data load into mysql, I have updated CR LF as space ' ' and load is working good.
it is not breaking it - you just need to do the load in a way that the issue isn't there - I (and others) gave you some options for it.
one of them (possibly the easiest for you) was to use a different line/row separator on both export and import. Did you do it?
and regardless of it you DO NOT update data like that just because a load to another system fails (incorrectly) - you replace it on the extract with something that you can then update back to what it was originally once the data is loaded (or as part of the load)
January 10, 2023 at 3:57 am
Thank you, I am planning the same to update some symbol.
I have tried different line/row separator, could not find how to export properly. The load data is working good if it does not have any breaking. Sometimes, I manually update notepad. But after fixing CR LF no manual update is needed, some places I see gibberish symbol ex - ÿ. I am manually removing those gibberish.
January 10, 2023 at 3:01 pm
Yes, default.
utf8mb4 - utf8mb4_0900_ai_ci
January 10, 2023 at 3:15 pm
You might want to replace “utf8mb4_0900_ai_ci” with “utf8mb4_general_ci” and “CHARSET=utf8mb4” with “CHARSET=utf8“.
😎
Question: have you checked that the binary format of the file matches the settings?
For UTF-8, the BOM (byte order mark) should be EF BB BF in HEX or  in text.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply