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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 trim empty spaces

Author  Topic 

Patyk
Yak Posting Veteran

74 Posts

Posted - 2014-09-22 : 12:47:00
i am inserting the following columns from one table to another,
SalesOrder,Customer,CustomerPoNumber,ShippingInstrs,CustomerName,ShipAddress1,ShipAddress2,ShipAddress3
How 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)),
...
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -