I am a newbie to ssis and am having issues with the loading the results of a stored procedure that includes NULL values into a table with ssis. What I have is follows:
Step 1
Execute Stored Procedure on Database1 will return a Full Result Set and put into ADO object User::CallResults
Step 2
Then I Loop through the results of User::CallResults mapping 2 variables:
Variable Index ADO object Type Nullable User::ID 0 Object NO User::Result 1 Object Yes
Step 3
Then in the Insert Row Into Database2 takes each row and executes “insert into dbo.myTable id, result values (?,?)”
I map ID as int and Result as long respectively.
When I execute I get the error:
failed with the following error: "An error occurred while extracting the
result into a variable of type (DBTYPE_I4)". Possible failure reasons:
Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established correctly.
Seems like this it errors when there is a null in the Result. Any suggestions to make ssis allow nulls?
You can achieve the process that you have described in the question using
Data Flow task. Here is a step by step description of fetching data using stored procedure and then inserting into a table, all done insideData Flow task. This example is just to give an idea of how this can be done and it uses only a single instance of SQL Server.Step-by-step process:
Create two tables named
dbo.Sourceanddbo.Destinationand populate the table dbo.Source with data as shown in screenshot #1. Create table scripts are provided under Scripts section.Create a stored procedure named
dbo.GetDatausing the script provided under Scripts section.On the SSIS package, create a variable named
StoredProcedureas shown in screenshot #2. This variable will contain the stored procedure execution statement.Create an
OLE DB Connectionin the Connection manager to connect to the SQL Server instance.On the
Control Flowtab of the SSIS package, place aData Flow taskas shown in screenshot #3.Double-click on the
Data flow taskto navigate to theData Flowtab. Inside the Data Flow tab, place anOLE DB Sourceand anOLE DB Destinationas shown in screenshot #4.Configure the
OLE DB Sourceas shown in screenshots #5 and #6. Notice that the source is using the variable that was created in step #3. The data returned by the stored procedure will be the source input.Configure the ‘OLE DB Destination` as shown in screenshots #7 and #8. This will insert the data into the destination table.
Screenshot #9 displays sample package execution.
Screenshot #10 shows the data in the tables after the package execution. Note that the destination table contains
NULLvalues. This is possible because the column Qty can acceptNULLvalues. However, if we had passedNULLvalues to the ItemNumber column, the package would have failed because the column is non-nullable.Hope that helps.
Scripts:
.
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10: