Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS Script Component, Allow Null values

I have a SSIS package that I am programming and my script component won't allow null column inputs. I have checked the box to keep nulls in the flat file source component. My program is running well until my script component where I get the error "The column has a null value" (super vague, I know). The column currently throwing the error is an "int" valued column and is used for aggregations in my script.

I could make the null values 0s or to say "NULL" but I'd prefer to just leave them blank.

I am using SQL Server BIDS 2008.

like image 245
user2471943 Avatar asked Jun 25 '13 22:06

user2471943


People also ask

How do I allow null values?

If you omit null or not null in the create table statement, Adaptive Server uses the null mode defined for the database (by default, NOT NULL). Use sp_dboption to set the allow nulls by default option to true.

How does SSIS handle blank values?

Solution: We will be using Derived Column Transformation in our SSIS Package to replace these blank values with Null. Drag Derived Column Transformation to Data Flow Pane and connect the Flat File Source to it. Add a new column DER_Address and write expression as shown below in fig 2.

How do you change a blank value to null in SSIS?

In SSIS First drag and drop the Data Flow Task component in the control flow. Inside the Data Flow Task, drag and drop the Flat File Source. Flat File Source read the blank space from the . txt file and converts it into NULL values.

How do you handle null values in group by?

If the grouping column contains a null value, that row becomes its own group in the results. If the grouping column contains more than one null value, all null values form a single group.


2 Answers

So because SSIS deals with the databases so much and doesn't want to spend a lot of time differentiating between DB NULL and C# NULL, they create boolean properties for each input column in the Buffer with the naming convention (columnname)_IsNull. You can read more about that on MSDN.

So you have to use those buffer columns to determine whether the value is null and then doing whatever you're trying to do with that column in the component.

So something like

if (!Row.MyColumn_IsNull) { 
//do something }
else {
//do something else, or nothing, etc.
}
like image 108
Kyle Hale Avatar answered Nov 22 '22 07:11

Kyle Hale


While Kyle's answer is very sufficient, I used a different method that is working just fine. I used the ternary for c#.

Value = Value_IsNull ? True Value : False Value;

Row.rowname = Row.rowname_IsNull ? 0 : Row.rowname;

This changed the value of my null integer columns to 0 if they were null coming into my script. Otherwise, it retained the value.

like image 32
user2471943 Avatar answered Nov 22 '22 07:11

user2471943