How do I validate date format to be mmddyyyy during data conversion in SSIS

Posted on 2009-02-12
Last Modified: 2013-11-10
I am importing a excel file and tryinng to convert data types to match the database types.
I have a date field in the source file. I used DB_TIMESTAMP during data conversion.
But when I run the package, it throws error on the rows where the date field is empty (ie, there is 'NULL' in the source file)
Also how do I make sure that the date is in mmddyyyy format?
Please help!
Question by:dorsun
    LVL 26

    Accepted Solution


    use an expression while you are converting i.e. you should do this control and conversion in a derived column component.

    FIELD_NAME == "" ? (DT_STR,8,1254)NULL(DT_STR,4,1254) : FIELD_NAME

    here 1254 is the code page and you should change it to your code page. this expression returns the date values and NULL for the empty ones.
    LVL 17

    Expert Comment

    Use a conditional expression: «boolean_expression» ? «when_true» : «when_false»
    Here is the expression, assuming your column from the file was Column 0. You also need to make sure the Destination table accepts NULL values in the date column.
    LEN(TRIM([Column 0])) > 1 ? (DT_DBTIMESTAMP)[Column 0] : NULL(DT_DBTIMESTAMP)  

    Author Closing Comment

    Thank you this worked

    Author Comment

    Hi tigin44,

    Your solution worked in the derived column. Later I had to use data conversion to convert to database type.
    The derived column type is string Unicode String [DT_WSTR]
    In data conversion I want to convert to DBTIMESTAMP. Since the data type of the column in the database is of datetime.
    When I run the package, I get an error 'Data conversion failed while converting column birth_date_dc(derived column) to column birth_date_db (database)

    Please help me out in this,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now