Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Pass Variable to Precendant Constraint Expand / Collapse
Author
Message
Posted Friday, May 1, 2009 12:15 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
This should be really straight forward and easy, but SSIS variables are not easy for whatever reason. I am trying to pass a simple count to a variable in my result set and use that count in a precedent constraint. If the value of the count is greater than 0, than continue with the package. The issue is however, that my variable is never increasing past 0.

Here are the details of my package:

Variable = CheckData
Scope = Package
Data Type = Int32
Value = 0

In an Execute SQL task I have the following configuration:
Result Set = Single Row
SQLStatement = SELECT COUNT(ID) AS CheckData FROM Table_A

In the Result Set window I have:
Result Name = CheckData
Variable Name = User::CheckData

I used a script task to identify the value of the variable and I am able to see that the value never increases past 0. Also, if I statically set the variable value to anything greater than 0 the package continues to execute. So the problem is obviously with the execute sql task not passing the value of my count to the variable.

I know my source table has data and the count is greater than 0. Why is my variable not getting the value from the count?



_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #708661
Posted Friday, May 1, 2009 1:08 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 6:29 PM
Points: 3,840, Visits: 3,852
Edit the precedence constraint and set the Evaluation operation setting to 'Expression'. Then use the Expression text box to check your variable value as such: @[User::CheckData] > 0.

You'll notice that the expression builder is not available here for whatever reason so you'll have to manually enter the expression. If you run into syntax errors, pull up an expression builder in another task and use it to build the expression, then cut/paste to the Precedence constraint.




John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Post #708707
Posted Friday, May 1, 2009 1:26 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
I should have mentioned in my original post, I have my precedant contraint set as such:

Evaluation operation = Expression and Constraint
Value = Success
Expression = @[User::CheckData] > 0
Logical AND


_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #708722
Posted Friday, May 1, 2009 1:34 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 6:29 PM
Points: 3,840, Visits: 3,852
Try just expression instead of expression and constraint.



John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Post #708732
Posted Friday, May 1, 2009 1:40 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
Same results. The excutes SQL task runs successfully, but never changes the variable value.

_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #708736
Posted Friday, May 1, 2009 1:43 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 6:29 PM
Points: 3,840, Visits: 3,852
Ah, my bad. I thought the problem was your precedence constraint. You are saying that:
The issue is however, that my variable is never increasing past 0.


What does the variable represent and how are you attempting to increment it's value?




John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Post #708739
Posted Friday, May 1, 2009 1:47 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
No problem.

Basically, I want to check if data is available in a table by doing "SELECT COUNT(ID) FROM Table_A". I want to pass the value of the count to a variable and check that variable in the precedent constraint. If the value is greater than 0, then execute the next task. If there are no records in the table, than the next package should not execute.

I am incrementing the variable, by passing the value of COUNT to the variable result set.


_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #708742
Posted Friday, May 1, 2009 1:54 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 12, 2014 6:29 PM
Points: 3,840, Visits: 3,852
I have a package that does the exact same thing. Here's how it is set up:

1. Package does some import stuff.
2. Execute SQL Task checks table row count:
- Result Set - Single Row
- Source - SELECT COUNT(*) as ProductionCount FROM Table
- Result Set tab
- Result Name - 0
- Variable name - User::ProductionCount
3. Precedence constraint w/ expression checking @User::ProductionCount > 0

Pretty simple in theory, but it seems like I always have to jump through a few hoops to get an Execute SQL task to populate the variable. In this case, I found that I needed to have the COUNT(*) alias match the variable name in SSIS. Wierd, but it works.

Are you using an Execute SQL task to populate your variable?




John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
Post #708746
Posted Friday, May 1, 2009 2:01 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
John Rowan (5/1/2009)
I have a package that does the exact same thing. Here's how it is set up:

1. Package does some import stuff.
2. Execute SQL Task checks table row count:
- Result Set - Single Row
- Source - SELECT COUNT(*) as ProductionCount FROM Table
- Result Set tab
- Result Name - 0
- Variable name - User::ProductionCount
3. Precedence constraint w/ expression checking @User::ProductionCount > 0

Pretty simple in theory, but it seems like I always have to jump through a few hoops to get an Execute SQL task to populate the variable. In this case, I found that I needed to have the COUNT(*) alias match the variable name in SSIS. Wierd, but it works.

Are you using an Execute SQL task to populate your variable?


Yes, I am using an execute SQL task to populate the variable. I noticed you set the result name to 0. I changed my result set name to 0 as well, but this still did not fix the issue.

This should in theory be very easy... thanks for your help thus far!


_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #708749
Posted Monday, May 4, 2009 2:26 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, March 28, 2013 12:21 PM
Points: 58, Visits: 199
I finally was able to resolve this issue.

Turns out that somehow 2 variables of the same name got created. When I looked at the variables though, it did not show that second variable until I clicked "Show all variables". One was created within the package scope and the other with the Execute SQL Statement scope.

Once I deleted the variable inside the Execute SQL Statement scope, the package ran as it should.


_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
Post #709725
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse