I would like to ask how can I pass an SSIS variable as a parameter of the used Stored Procedure by OLE DB Command in Data Flow?
I am trying to write the following as SQL Command, but not working: EXEC [dbo].[CalculateProcess] ?,?,?
Received error:
No value given for one or more required parameters.
The first and second values (? values) are coming from Flat File Source as ID, and NAME. The third one should be the value of SSIS variable @howMany. How can I do it? Thanks for help.
EDIT:
Lets assume my dataset is:
ID NAME
1 X
2 Y
3 Z
4
5 A
In this case, @howMany should be 4 at the end. The value should be updated dynamically after each OLE DB Command works if current NAME is not null.
ID NAME
1 X
@howMany = 1
2 Y
@howMany = 2
3 Z
@howMany = 3
4
@howMany = 3
5 A
@howMany = 4
EDIT 2: When I do add @howMany as derived column, it is happening like:
ID NAME @howMany
1 X 0
2 Y 0
3 Z 0
4 0
5 A 0
And the 0 values are staying, not getting updated after each row. writing OUTPUT after ? in the SQL command did not solve it? Where is my mistake?
EDIT 3: Stored Procedure is --
CREATE PROCEDURE [dbo].[CalculateProcess]
@ID int,
@name varchar(30),
@howMany int output
AS
BEGIN
SET NOCOUNT ON;
if (@name is not null)
BEGIN
set @howMany = @howMany + 1;
END
END
EDIT 4: I added a Script Component right after getting Flat File Source. Name is the INPUT parameter, NameCounter is my output column. My script is:
private int nameCounter;
public override void PreExecute()
{
nameCounter= 0;
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (Row.Name != null)
{
nameCounter++;
}
Row.NameCounter= nameCounter;
}
The Script Component is connected to my OLE DB Command. This is generating a column called NameCounter and adding it to all data in the OLE DB Command. Now I just dont know how to get the value of NameCounter here and assign it to an SSIS variable?
@howManyis this an OUTPUT variable ?@Howmanyvariable is always null unless you pass a value to it at run-time, since the only values you have is theIDandNameyourHowmanyvariable will always be null in this case. And where is yourUPDATEstatement in the procedure ?