SSIS date with a value as '-' should be inserted as null

  • In an SSIS package I am using a Excel source with a date column, and some of the dates are hyphen . I want these hyphens to be treated as null when the data from the file is loaded into the database. when I execute the task I get the error "The value could not be converted because of a potential loss of data". How can I get the SSIS package to treat the hyphen date strings as nulls?

    Aditi:-)

  • hi,

    Try script component between excel source and database destination.

    In script component use a function , if '-' then null.

    insert the column into database as null value..

    Regards,
    Gayathri ๐Ÿ™‚

  • gayathridevi.msit (7/15/2010)


    hi,

    Try script component between excel source and database destination.

    In script component use a function , if '-' then null.

    insert the column into database as null value..

    That will do it, but a derived column is simpler and faster ...

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Thanks Phil ,

    But i am Novice to SSIS ..Can you tell me how to do it in derived columns ..what about the other columns ..they also need conversion ..so can i use them all in Derived ...

  • itsaditi2001 (7/15/2010)


    But i am Novice to SSIS ..Can you tell me how to do it in derived columns ..what about the other columns ..they also need conversion ..so can i use them all in Derived ...

    Use the FINDSTRING function in your derived column. If it finds a result, set null (see the NULL functions), otherwise take the original value. Use the (expression0) ? (result if true) : (result if false) syntax to achieve this.

    You need to create a new expression for every column you want to convert.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I tried this ...

    its not working for me..

    TRIM([STARTD_CVV] ) == FINDSTRING( STARTD_CVV, "-", 1 ) ? (DT_STR, 8, 1252)NULL(DT_STR,8, 1252) :[STARTD_CVV]

  • itsaditi2001 (7/15/2010)


    I tried this ...

    its not working for me..

    TRIM([STARTD_CVV] ) == FINDSTRING( STARTD_CVV, "-", 1 ) ? (DT_STR, 8, 1252)NULL(DT_STR,8, 1252) :[STARTD_CVV]

    Try the following:

    (FINDSTRING(TRIM([STARTD_CVV]), "-",1) > 0) ? NULL(DT_STR, 8,1252) : [STARTD_CVV]

    EDIT: for some reason, the site placed & gt; instead of a >

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Error at Data Flow Task [Derived Column [134]]: Attempt to parse the expression "FINDSTRING((TRIM(STARTD_CVV), "-",1) > 0 ) ? NULL(DT_STR, 8,1252) : STARTD_CVV" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

    Cannot parse... what i m missing

  • You left out the square brackets around the field name ...

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin (7/15/2010)


    You left out the square brackets around the field name ...

    No, that is only necessary when the field name contains a space.

    I think he forgot the initial (. (what is it called in English, parenthesis?)

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • da-zero (7/15/2010)


    Phil Parkin (7/15/2010)


    You left out the square brackets around the field name ...

    No, that is only necessary when the field name contains a space.

    I think he forgot the initial (. (what is it called in English, parenthesis?)

    Oh indeed. Well spotted.

    'Parenthesis' is the fancy term, though I would refer to the initial '(' as the 'opening bracket'.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • itsaditi2001 (7/15/2010)


    In an SSIS package I am using a Excel source with a date column, and some of the dates are hyphen . I want these hyphens to be treated as null when the data from the file is loaded into the database. when I execute the task I get the error "The value could not be converted because of a potential loss of data". How can I get the SSIS package to treat the hyphen date strings as nulls?

    Aditi:-)

    Don't load directly from Excel into a production table, use a staging table. Design the staging table to optimise the process of data capture from the source, thus eliminating errors like "The value could not be converted because of a potential loss of data". Add extra columns for processing if you wish.

    Everything inside your database is valuable, everything outside is garbage. A staging table serves as a firewall between the two.

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 12 posts - 1 through 11 (of 11 total)

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