1

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?

2
  • Is there a reason you're doing this in the Control flow instead of creating a ata flow? What you're doing is exactly what the data flow is created for. Apr 29, 2011 at 16:57
  • I will look into that, this was my first pass at solving the problem.
    – Haeflinger
    Apr 29, 2011 at 19:42

3 Answers 3

3

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 inside Data 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:

  1. Create two tables named dbo.Source and dbo.Destination and populate the table dbo.Source with data as shown in screenshot #1. Create table scripts are provided under Scripts section.

  2. Create a stored procedure named dbo.GetData using the script provided under Scripts section.

  3. On the SSIS package, create a variable named StoredProcedure as shown in screenshot #2. This variable will contain the stored procedure execution statement.

  4. Create an OLE DB Connection in the Connection manager to connect to the SQL Server instance.

  5. On the Control Flow tab of the SSIS package, place a Data Flow task as shown in screenshot #3.

  6. Double-click on the Data flow task to navigate to the Data Flow tab. Inside the Data Flow tab, place an OLE DB Source and an OLE DB Destination as shown in screenshot #4.

  7. Configure the OLE DB Source as 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.

  8. Configure the 'OLE DB Destination` as shown in screenshots #7 and #8. This will insert the data into the destination table.

  9. Screenshot #9 displays sample package execution.

  10. Screenshot #10 shows the data in the tables after the package execution. Note that the destination table contains NULL values. This is possible because the column Qty can accept NULL values. However, if we had passed NULL values to the ItemNumber column, the package would have failed because the column is non-nullable.

Hope that helps.

Scripts: .

CREATE TABLE [dbo].[Destination](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ItemNumber] [varchar](50) NOT NULL,
    [Qty] [int] NULL,
CONSTRAINT [PK_Destination] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Source](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ItemNumber] [varchar](50) NOT NULL,
    [Qty] [int] NULL,
CONSTRAINT [PK_Source] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

CREATE PROCEDURE [dbo].[GetData]
AS
BEGIN
    SET NOCOUNT ON;

    SELECT      Id
            ,   ItemNumber
            ,   Qty
    FROM        dbo.Source
END
GO

Screenshot #1:

1

Screenshot #2:

2

Screenshot #3:

3

Screenshot #4:

4

Screenshot #5:

5

Screenshot #6:

6

Screenshot #7:

7

Screenshot #8:

8

Screenshot #9:

9

Screenshot #10:

10

1

Not really an answer, but since code can't be formatted nicely in a comment I'm putting it here.

Do you realize, that if your databases are on the same server, you can do this:

INSERT INTO 
    database1.dbo.Results
EXEC 
    database2.dbo.SampleStoredProcedure @param1, @param2, @param3
1
  • Unfortunately they are on different servers and have to use different credentials to access. Thanks I can see uses for this in other projects.
    – Haeflinger
    May 9, 2011 at 13:38
0

Put this logic into a Data Flow. After that is accomplished, just do a bulk insert and it should allow the nulls through.

SSIS - Unable to insert NULL for Blank fields in BULK INSERT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.