sql-serverssisetloledbconditional-split

SSIS Expression to handle NULLs in multiple columns


I have an OLE DB source that has some nulls, it has 50 columns and I'm trying to extract the rows that have NULLs to Bad data destination, the expression that I had for the conditional split is

ISNULL([StudentName]) == TRUE

But that means I have to repeat it for all the columns that I have and I'm wondering if there's another way to handle this. especially since I have multiple tables to process. Thanks


Solution

  • Believe it or not this has been puzzling me since you posted it.

    I have not figured a way to do it SSIS but here is a possible solution using a script component source. This will find all the keys associated with a row that has at least one null column.

        DataTable dt = new DataTable();
    
        string sql = "Enter your extract SQL here";
        using(OleDbConnection conn = new OleDbConnection("Data Source=XXXXXXXXX;Initial Catalog=YYYYY;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;"))
        {
            using (OleDbCommand cmd = new OleDbCommand(sql,conn))
            {
                cmd.CommandType = CommandType.Text;
                conn.Open();
                dt.Load(cmd.ExecuteReader());
            }
        }
    
        foreach (DataRow row in dt.Rows)
        {
            foreach (DataColumn col in dt.Columns)
            {
                if (row[col] == DBNull.Value)
                {
                    Output0Buffer.AddRow();
                    Output0Buffer.NullRowKey = row.Field<int>(0); //This is the 0 based index of the key in the data
                    break;
                }
            }
        }
    

    The problem I was running into was trying to use Columns in an Output0Buffer data type which is what you have to use when using Script Component of a transformation. I need to actually use script component source and load the data into a data table in order to have access to a Columns property.