Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SSIS Result Set and Stored Procedure

Posted on 2016-07-22
5
Medium Priority
?
35 Views
Last Modified: 2016-07-25
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.
0
Comment
Question by:barkome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:DcpKing
ID: 41726037
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
 

Author Comment

by:barkome
ID: 41726142
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
 
LVL 16

Accepted Solution

by:
DcpKing earned 2000 total points
ID: 41726771
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
 

Author Comment

by:barkome
ID: 41726980
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
 
LVL 16

Expert Comment

by:DcpKing
ID: 41727476
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Expressions are in essence, code. If you had an expression 2 + 2 it would evaluate to 4. A string expression of “Hello” + “ “ + “World” would evaluate to “Hello World”. Expressions are an excellent choice for working with dynamic variables, espec…
A couple of weeks ago, my client requested me to implement a SSIS package that allows them to download their files from a FTP server and archives them. Microsoft SSIS is the powerful tool which allows us to proceed multiple files at same time even w…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question