I imported an Excel sheet with countries into a database table.
Unfortunately all rows have some leading empty space.
So, how can I delete these empty spaces?
Basically it performs three steps: Replace each 0 with a space – REPLACE([CustomerKey], '0', ' ') Use the LTRIM string function to trim leading spaces – LTRIM(<Step #1 Result>) Lastly, replace all spaces back to 0 – REPLACE(<Step #2 Result>, ' ', '0')
Export all the rows to a new table and move the rows back. This reorganizes the LOB data and release the unused space. Use DBCC SHRINKFILE with EMPTYFILE option to move all the data to a newly added data file and then remove old data file. This reorganizes the LOB data there by releasing the unused space.
This will remove leading and trailing spaces
Update tablename set fieldName = ltrim(rtrim(fieldName));
some versions of SQL Support
Update tablename set fieldName = trim(fieldName);
If you just want to remove leading
update tablename set fieldName = LTRIM(fieldName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With