0
votes

How do I load null vaules in integer datat type file?

I want load csv file data into sql server table using ssis package.

Source csv file emp data is

id | Name |  deptno
1  |ab    |NULL
2  |      |NULL
3  |dhd   |NULL

Target sql server table emp:

id int, name varchar(50), deptno int

I treid datatype using showadvaned mode for external columns and output columns as per target table datatypes

after that I execute the package .here i am unable to load null values in int deptno filed

and getting errors like below :

[OLE DB Destination [27]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".

[OLE DB Destination [27]] Error: There was an error with OLE DB Destination.Inputs[OLE DB Destination Input].Columns[depno] 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 [27]] 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" (27) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (40). 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.

I tried another way using derived column : UPPER([deptno]) == "NULL" ? NULL(DT_I4) : [deptno] this also giving error

enter image description here

Can you please tell me how to load null values in sql server tables for integer datatypes using ssis packages?

1

1 Answers

1
votes

start with data type as varchar(25)

and then derive your integer column using your formula:

UPPER([deptno]) == "NULL" ? NULL(DT_I4) : (DT_I4)[deptno]

I think you just forgot to add the final cast.

You are going to need to do this for all non-numbers in your csv. So most likely an empty string ("") as well.

So...

UPPER([deptno]) == "NULL" ? NULL(DT_I4) : deptno == "" ? null(DT_I4) :(DT_I4)[deptno]