1

I want to know if is possible save a PRINT SQL text into SSIS variable.

My query is:

IF EXISTS (SELECT * FROM TABLE WHERE month = '1' or month = '2' or month = '3' or month = '4' 
            or month = '5' or month = '6' or month = '7' or month = '8' or month = '9')
BEGIN
PRINT = 'EXIST' 
END
ELSE
BEGIN
PRINT = 'NOT_EXIST'  
END

I need exist or not_exist to execute a flowfile or another. I tried with ResultSet(SingleRow) but I am not able. What its the best way?

Thanks

4
  • Just change your PRINT to SELECT 'EXIST' AS Status and SELECT 'NOT_EXIST' AS Status set the result set on the execute sql task to single row then on the Result Set page map it your variable. Result Name would be Status and then pick your variable. Commented Jan 21, 2021 at 22:00
  • Thanks @TimMylott !! :) and can i execute one flow or another depending on the content of the variable?? Commented Jan 21, 2021 at 22:55
  • @TimMylott Subqueries are not allowed in that context, you can't use PRINT with SELECT Commented Jan 22, 2021 at 10:57
  • @SandraGuilepZouaouiZandeh you're correct, I wasn't saying use print with select. Your answer is an option as well using an OUTPUT, both would have accomplished the same thing. Commented Jan 22, 2021 at 14:41

1 Answer 1

1

You can create a stored with your query like below :

ALTER PROCEDURE [dbo].[proc_testExistence]  (
@Result  varchar(10) OUTPUT ) AS

BEGIN

IF EXISTS (IF EXISTS (SELECT * FROM TABLE WHERE IN ('1','2','3','4','5','6','7','8','9'))
     SELECT @Result = 'Success';
ELSE
     SELECT @Result = 'Failure';
END

Then create a variable named vResult in your SSIS package : enter image description here

Then in your SQL Task, in the SQL Statement :

EXEC  proc_testExistence ? OUTPUT

Create this mapping :

enter image description here

Modify the Precedence Constraint for the first condition Success :

enter image description here

And for the second condition Failure :

enter image description here

Your flow is something similar to this :

enter image description here

You can add a breakpoint as above to check the value of your variable during debugging.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.