In this tutorial, I will show how to handle a NULL value loaded by SSIS from a CSV file. Note that some knowledge of Excel, SQL and programming is necessary.
1. Build a CSV file. Here’s a sample file:
2. Create a table in the SQL server database:
create table employee
employeeid varchar(10) not null,
name varchar(100) not null,
hiredate datetime not null,
terminatedate datetime null,
job varchar(100) null,
seq int IDENTITY(1,1) NOT NULL
create unique clustered index PK on employee (seq)
3. Start SSIS and create a new package. My example is ImportCSV.dtsx
4. Build the SSIS package and run the package:
5. After running the package, you can see the Execution Results shows the following errors even though we have set the terminatedate field to be a NULL value:
[OLE DB Destination ] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: “Microsoft SQL Server Native Client 11.0” Hresult: 0x80004005 Description: “Invalid character value for cast specification”.
[OLE DB Destination ] Error: There was an error with OLE DB Destination.Inputs[OLE DB Destination Input].Columns[terminatedate] on OLE DB Destination.Inputs[OLE DB Destination Input]. The column status returned was: “The value could not be converted because of a potential loss of data.”
[OLE DB Destination ] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The “OLE DB Destination.Inputs[OLE DB Destination Input]” failed because error code 0xC0209077 occurred, and the error row disposition on “OLE DB Destination.Inputs[OLE DB Destination Input]” specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component “OLE DB Destination” (31) failed with error code 0xC0209029 while processing input “OLE DB Destination Input” (44). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
6. The solution is to add a script component. Open the script component and enable all the fields on the Input Columns:
7. Then Inputs and Outputs, add a field in the Output and set the DataType to string:
8. Modify the script and the code to the Input0_ProcessInputRow method:
if (string.IsNullOrEmpty(Row.terminatedate) || Row.terminatedate_IsNull)
Row.TerminateValue = “01/01/1900”;
Row.TerminateValue = Row.terminatedate.ToString();
9. Put the link together with the Flat File Source to Script Component and to OLE DB Destination. Then go back to the OLE DB Destination and remap terminatedate to TerminateValue:
10. Run it and you should see no errors this time:
11. Look in the SQL server database backend and you can see that the terminate field contains the default value:
Note this solution can also be applied to other file types besides CSV. As always, please contact the specialists at MIBAR with any questions or for additional support.