SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Pass Variable to Precendant Constraint


Pass Variable to Precendant Constraint

Author
Message
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 199
This should be really straight forward and easy, but SSIS variables are not easy for whatever reason. Angry 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]
John Rowan
John Rowan
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9768 Visits: 4579
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
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 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]
John Rowan
John Rowan
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9768 Visits: 4579
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
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 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]
John Rowan
John Rowan
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9768 Visits: 4579
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
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 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]
John Rowan
John Rowan
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9768 Visits: 4579
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:TongueroductionCount
3. Precedence constraint w/ expression checking @User:TongueroductionCount > 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
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 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:TongueroductionCount
3. Precedence constraint w/ expression checking @User:TongueroductionCount > 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]
Jody Claggett-376930
Jody Claggett-376930
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 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]
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search