SQL Server Business Intelligence

SQL SERVER 2005 & 2008 IS THE MAIN THEME OF THIS BLOG

Tuesday, March 14, 2006

Null field in Fixed Length File Which Should be an Integer Column

The project I am currently working get source files in a fixed length format. Some fields allowed to have nulls, and some are integer fields.

I ran into a problem if I define the field as integer column in the connection manager. The reason for that is that those fields which supposed to be nulls, are not really nulls, they are spaces. To overcome this I did the following


* Define the column as DB_STR in the flat file connection manager.
* Once the data is read from the data source I added Derived Column in the next step.
* I added a new derived column with the following expression
(DT_UI4)((TRIM([GrpId]) == "") ? NULL(DT_WSTR,0) : [GrpId])

The above statement will TRIM the spaces out from a column called GrpId and if GrpId is equal to “”, then it will set it to be null, else it will assign the value of GrpId. Finally (DT_UI4) statement will convert the return result set to Four Byte Unsigned Integer.

Thanks
Sutha

0 Comments:

Post a Comment

<< Home