I have the following tasks in SSIS:
In Check Stock task, I execute a stored procedure which returns 0 or 1:
CREATE PROCEDURE [dbo].[SP_CheckStockAvailability]
AS
BEGIN
DECLARE @ItemGID nvarchar(250)=(SELECT TOP (1) ItemGID FROM XMLOrderlines WHERE Comparison='0')
SELECT CASE
WHEN @ItemGID IS NOT NULL
THEN CAST (0 AS bit)
ELSE CAST (1 AS bit)
END AS Comparison
FROM XMLOrderlines
END
GO
I would like to execute Reject Order (on the right) task if the result is 1 and, if not, to execute the one from the left. I set to export the result of the procedure in a variable, Boolean
data type with a default value of "False".
If I edit the precedence constraint and I set Expression
as evaluation operation and then choose the variable from the previous task, either way it does not go to the next task that is supposed to. What am I missing? I tried what I found on the web but nothing helped me. Thanks!
The precedence constraint uses a constraint value, an expression, both, or either to determine whether the constrained executable runs. If the precedence constraint uses an execution result, you can specify the execution result to be success, failure, or completion.
Add a SSIS Conditional Split Transformation to the Data Flow The Conditional Split Transformation task checks for the specified condition. It moves the data to an appropriate destination depending upon the condition. Drag the SSIS Conditional Split task from the SSIS Toolbox.
It defines how many tasks (executables) can run simultaneously. It defaults to -1 which is translated to the number of processors plus 2.
The Execute Package task in SSIS allows us to call packages present in the Same Project, File system, and SQL Server.
You have to set the following values:
Reject Order
Evaluation operation: Expression and Constraint
Value: Success
Expression: @[User::Result] = 1
OR
@[User::Result]
Accept Order
Evaluation operation: Expression and Constraint
Value: Success
Expression: @[User::Result] = 0
OR
!@[User::Result]
Screenshot
I think it is better to add a TRY...CATCH
block to your procedure, so if it encounters an error the result will be 1
and the Order is rejected:
CREATE PROCEDURE [dbo].[SP_CheckStockAvailability]
AS
BEGIN
BEGIN TRY
DECLARE @ItemGID nvarchar(250)=(SELECT TOP (1) ItemGID FROM XMLOrderlines WHERE Comparison='0')
SELECT CASE
WHEN @ItemGID IS NOT NULL
THEN CAST (0 AS bit)
ELSE CAST (1 AS bit)
END AS Comparison
FROM XMLOrderlines
END TRY
BEGIN CATCH
SELECT 1 AS Comparison
END CATCH
END
GO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With