How to trim data in column with sql
To trim newline characters from a text field in SQL database, you can use the trim()
function along with the replace()
function. Here’s how you can do it:
UPDATE your_table
SET your_column = trim(replace(replace(your_column, char(10), ''), char(13), ''))
This SQL statement does the following:
replace(your_column, char(10), '')
removes line feeds (LF, \n)
replace(..., char(13), '')
removes carriage returns (CR, \r)
trim(...)
removes any leading or trailing whitespace
This approach handles both Unix-style (LF) and Windows-style (CR+LF) line endings.