sql server 2005 - How to handle NULL values returned by a stored procedure from within SSIS package? -
i newbie ssis , having issues loading results of stored procedure includes null values table ssis. have follows:
step 1
execute stored procedure on database1 return full result set , put ado object user::callresults
step 2
then loop through 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 insert row database2 takes each row , executes "insert dbo.mytable id, result values (?,?)"
i map id int , result long respectively.
when execute error:
failed following error: "an error occurred while extracting result variable of type (dbtype_i4)". possible failure reasons: problems query, "resultset" property not set correctly, parameters not set correctly, or connection not established correctly.
seems errors when there null in result. suggestions make ssis allow nulls?
you can achieve process have described in question using data flow task. here step step description of fetching data using stored procedure , inserting table, done inside data flow task. example give idea of how can done , uses single instance of sql server.
step-by-step process:
create 2 tables named
dbo.source,dbo.destination, populate table dbo.source data shown in screenshot #1. create table scripts provided under scripts section.create stored procedure named
dbo.getdatausing script provided under scripts section.on ssis package, create variable named
storedprocedureshown in screenshot #2. variable contain stored procedure execution statement.create
ole db connectionin connection manager connect sql server instance.on
control flowtab of ssis package, placedata flow taskshown in screenshot #3.double-click on
data flow tasknavigatedata flowtab. inside data flow tab, placeole db source,ole db destinationshown in screenshot #4.configure
ole db sourceshown in screenshots #5 , #6. notice source using variable created in step #3. data returned stored procedure source input.configure 'ole db destination` shown in screenshots #7 , #8. insert data destination table.
screenshot #9 displays sample package execution.
screenshot #10 shows data in tables after package execution. note destination table contains
nullvalues. possible because column qty can acceptnullvalues. however, if had passednullvalues itemnumber column, package have failed because column non-nullable.
hope 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] begin set nocount on; select id , itemnumber , qty dbo.source end go screenshot #1:

screenshot #2:

screenshot #3:

screenshot #4:

screenshot #5:

screenshot #6:

screenshot #7:

screenshot #8:

screenshot #9:

screenshot #10:

Comments
Post a Comment