Search code examples
sql-serverdatetimessisnullssis-2012

Nullable Datetime From Derived Column


Extracting data from a flat file. Field in question comes in as a string and is formatted to fit db column of type Datetime. Field allows null in the database and file contains nulls and valid strings that successfully convert to dates in this field.

SSIS is throwing an error when I try and pass the nulls on to the database.

Error

Error: An exception has occurred during data insertion, the message returned from the provider is: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Data Conversion Code

([PO Scheduled Ship Date] == "") ? NULL(DT_DBTIMESTAMP) : (DT_DBTIMESTAMP)(SUBSTRING([PO Scheduled Ship Date],1,4) + "-" + SUBSTRING([PO Scheduled Ship Date],5,2) + "-" + SUBSTRING([PO Scheduled Ship Date],7,2))

DataViewer Sample

DataViewer Sample

DB Column Definition

DB Column Definition


Solution

  • Culprit was data outside of the date range ex. "00010101".