Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
i am inserting the following columns from one table to another, SalesOrder,Customer,CustomerPoNumber,ShippingInstrs,CustomerName,ShipAddress1,ShipAddress2,ShipAddress3How do I make sure that all empty spaces are trimmed.Thanks
gbritton
Master Smack Fu Yak Hacker
2780 Posts
Posted - 2014-09-22 : 16:39:57
Make the destination columns varchar or nvarchar, or code like this:
insert ...select ltrim(rtrim(Customer)), ...
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2014-09-22 : 16:40:26
If you want to trim only leading and trailing spaces (assuming they are space characters):
INSERT INTO DestinationTable( SalesOrder, Customer,....)SELECT( LTRIM(RTRIM(SalesOrder)), LTRIM(RTRIM(Customer)), ...)FROM SourceTable
If you want to remove ALL spaces including embedded spaces, use REPLACE instead of LTRIM and RTRIM