TRIM

  • Hey guys,

    I am importing a data file in SSIS and as I was doing the import I got an error message saying "The value could not be converted because of a potential loss of data.". So I first went and checked and made sure the source and destination columns were set to the same data type and length...And they were! So my next step was to look at the data...Well that was the problem - the destination column is a varchar(1)...well in the data file - for that column was - |dddddddddd| So that is what it throwing that error...So I was wondering if there was an expression I could use in the Derive Column Transformation for that column that I could trim that down to just the first letter?

    Any suggestions?

    Thanks in advance!

  • Look up SUBSTRING and see if that's what you're thinking.

  • asm1212 (6/8/2011)


    Hey guys,

    I am importing a data file in SSIS and as I was doing the import I got an error message saying "The value could not be converted because of a potential loss of data.". So I first went and checked and made sure the source and destination columns were set to the same data type and length...And they were! So my next step was to look at the data...Well that was the problem - the destination column is a varchar(1)...well in the data file - for that column was - |dddddddddd| So that is what it throwing that error...So I was wondering if there was an expression I could use in the Derive Column Transformation for that column that I could trim that down to just the first letter?

    Any suggestions?

    Thanks in advance!

    Either change the column to a size large enough to hold the data or look into some string manipulation.

    btw, varchar(1) is really a waste of space. It takes the length of the data + 2 bytes. So each row that has a value in this field is consuming 3 bytes of storage space to hold a single byte. Not a huge deal with 100 rows but when you get to a million or more...well at least disc space is cheap. 😛

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply