SSIS Result Set and Stored Procedure

Hello

I have a SSIS SQL Task-1that calls a stored procedure with 3 columns - Name, Number and ID with multiple rows which is then stored in an object variable for another SQL Task-2 to use the ID as an input.

Task 1 Output:
name, number, ID
A,2,3
B,3,4
C,5,6

The foreach loop workflow is:

- Truncate stage table,
- load data for name A,
- stored procedure to get value for name A and load into destination table,
- move data file for name A to archive....

then repeat the process for  name B, then name C one after the other..

Does anyone know the best way that I can get SQL Task-2 to use the ID's from Task-1 one by one and not use all of ID's at the same time.

As it is now, task 2 is processing all of the ID's and creating values to the destination table as:

Name, ID, value
A, 3, 300
B, 4, 0
C, 6, 0

Values for Name B and C is appearing 0 Because data for both of them is not loaded because the foreach loop is not repeating the workflow from step 1 for each of them.
barkomeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DcpKingCommented:
Have you tried arranging things so that Task 1 only emits records for A and B and not C? If you do that, does Task 2 still provide the same results? In that case I'd suggest that your problem is with Task 2 and not your SSIS.

hth

Mike
0
barkomeAuthor Commented:
Yeah, I did so...

I have a stored procedure that creates a data set with ID's, which is then sent to a Foreach Loop ADO Enumerator. Within the Foreach Loop are two stored procedures: The first SP, works as expected, but the second one fails, because its receiving just the first ID presented, and not looping through like the first SP.

Below is a image of the flow.

Foreach-Loop.png
The logic is, 3 ID's are retrieved 1,2 and 3. Task 1 which is the first SP, will execute with ID 1 as an input, and when complete pass that same ID (1) to Task 2 for the second SP to execute with.

Once this loop is complete, the logic/workflow will start again from task 1 with ID 2, and once complete, start again from task 1 again but this time with ID 3.
0
DcpKingCommented:
Well, what I've done is create a very small SSIS package that does roughly what you're trying to do, excepting, of course, that it has none of your data or tables. Make yourself the three procs below and the SSIS package. I believe I've included everything you need, and it should just work! Then you should be able to compare it with your version to see where you're maybe going wrong.


The whole thing is in pic 1. Pics 2 and 3 show how data from the first procedure (Barkome_0) is brought into an Object for use by the ForEach loop.
alter procedure Barkome_0
as
/*
exec Barkome_0
*/
begin
	set nocount on
	declare @ta table (Name varchar(8), Number int, ID int)
	insert into @ta(Name, Number, ID)
		values
		('A',2,3),
		('B',3,4), 
		('C',5,6)
	select ID from @ta
End

Open in new window


Then there are pictures showing the general and result set dialogs for Task 1 and Task 2, and a list of the variables.

The script tasks are simply there to produce pop-up boxes telling you what the variables are ... the code is just this:
public void Main()
         {
MessageBox.Show(Dts.Variables["User::YourVariableNameHere"].Value.ToString(), "Message Box Title Here");
         }

Open in new window


The variables for the commands for the two tasks are these:

"exec Barkome_1 " +  (DT_WSTR, 3) @[User::intID]
"exec Barkome_2 " +  (DT_WSTR, 3) @[User::intID] + ", " +  (DT_WSTR, 3) @[User::intNumber]

and the code for the two tasks is as follows:
ALTER procedure [dbo].[Barkome_1]
(
	@intID int
)
as
/*
exec Barkome_1 4
*/
begin
	set nocount on
	declare @strName varchar(8), @intNumber int
--	----------------------------------
	declare @ta table (Name varchar(8), Number int, ID int)
	insert into @ta(Name, Number, ID)
		values
		('A',2,3),
		('B',3,4), 
		('C',5,6)
	select	@strName = Name, 
			@intNumber = Number
	from @ta 
	where ID = @intID
--	----------------------------------
	select @strName as 'Name', @intNumber as 'Number', @intID as 'ID'
End

Open in new window

alter procedure Barkome_2
(
	@id int,
	@number int
)
as
/*
exec Barkome_2 4, 3
*/
begin
	set nocount on
	declare @ta table (ID int, Constant int)
	insert into @ta(ID, Constant)
		values
		(3, 29),
		(4, 42), 
		(6, 17)
	declare @result int 
	set @result = (select Constant from @ta where ID = @id)
	set @result = @result * @number
	select @id as 'ID', @result as 'Value'
End

Open in new window

Screenshot-from-2016-07-24-17-10-24.png
Screenshot-from-2016-07-24-17-10-58.png
Screenshot-from-2016-07-24-17-11-15.png
Screenshot-from-2016-07-24-17-17-55.png
Screenshot-from-2016-07-24-17-18-17.png
Screenshot-from-2016-07-24-17-18-44.png
Screenshot-from-2016-07-24-17-19-00.png
Screenshot-from-2016-07-24-17-19-48.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
barkomeAuthor Commented:
Thanks for this Task 1 works perfectly well when Task 2 is not part of the workflow, loading the right values one after the other.

Did some digging around and noticed that it had to do with the data type. applied the CAST syntax to the affected columns and it suddenly worked as expected, but only for it to duplicate a few records with a default value of 0.00
0
DcpKingCommented:
Take a look at my Task 2 and compare it with yours. Is yours getting the data it needs? If not, have some way of recording what it does get (write the values out to a table) and look at them there. Look at the way that I'm splitting out the values that are passed from task to task into variables. Are you trying to keep them in an object or something? Putting them in variables whose value changes each time around the loop is a lot more reliable and easier to debug.

Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSIS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.