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
 RTRIM(LTRIM()) for import

Author  Topic 

Robowski
Posting Yak Master

101 Posts

Posted - 2013-02-25 : 06:59:41
If importing directly from a csv file, is it possible to apply the rtrim(ltrim function for the direct import?


BULK
INSERT
#table
FROM
'\\filepath'
WITH
(
FIELDTERMINATOR = ','
,ROWTERMINATOR = '\n'
)

or is it simply a case of running the below after it?

UPDATE
#Table
SET
field1 = LTRIM(RTRIM(UPPER(field1)))
,field2 = LTRIM(RTRIM(UPPER(field2)))
,field3 = LTRIM(RTRIM(UPPER(field3)))
,field4 = LTRIM(RTRIM(UPPER(Gfield4)))

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-25 : 07:28:50
Bulk insert does not have an option that will allow you to intercept the data on its way into the table and LTRIM/RTRIM it. What you suggested - updating the table after the insert - is perhaps the best course of action.
Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 2013-02-25 : 10:23:05
quote:
Originally posted by James K

Bulk insert does not have an option that will allow you to intercept the data on its way into the table and LTRIM/RTRIM it. What you suggested - updating the table after the insert - is perhaps the best course of action.



Thanks
Go to Top of Page
   

- Advertisement -