Import Excel into SQL - Datetime conversion fail

0

I'm trying to import a excel into my SQL Database but I'm getting this error:

Messages Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "Conversion failed when converting date and/or time from character string.". (SQL Server Import and Export Wizard)

The database expects this data:

    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    public DateTime hechosf_periodo { get; set; }

A sample of how this data is stored:

enter image description here

And this is how the data is entered into the Excel:

enter image description here

SQL identifies the excel column as datetime and will try to convert it to datetime2.

What can I do in order to pass this error?

enter image description here

Update:

After reviewing the Post-execute report

enter image description here

I've seen that is trying to read more rows that are empty. I've trying deleting the content of every cell in the sheet but this still persists.

sql-server
excel
import

1 Answer

0

You should to use Derived Column Transformation between the Source and Destination elements in your flow, which descripted here.

Are you see an @[System::StartTime] variable? You should to add your column (from the left pane) instead of this variable, and to choose the appropriate type in casting function from Type Casts folder (see the rigth pane). See mapping between the SSIS and the SQL types at this page.
It will be DT_DBTIMESTAMP of DT_DBTIMESTAMP2, and an expression will looks like a [DT_DBTIMESTAMP]old_column_name. In Derived Column you need to left option "add new...", then you need to name this new column and use this new in the Destination element instead of excel "time" column.
enter image description here

answered on Stack Overflow Nov 27, 2018 by mchist

User contributions licensed under CC BY-SA 3.0