May 1, 2009 at 12:15 pm
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?
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 1, 2009 at 1:08 pm
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.
May 1, 2009 at 1:26 pm
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
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 1, 2009 at 1:34 pm
May 1, 2009 at 1:40 pm
Same results. The excutes SQL task runs successfully, but never changes the variable value.
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 1, 2009 at 1:43 pm
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?
May 1, 2009 at 1:47 pm
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.
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 1, 2009 at 1:54 pm
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?
May 1, 2009 at 2:01 pm
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!
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 4, 2009 at 2:26 pm
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.
_______________________________
[font="Tahoma"]Jody Claggett
SQL Server Reporting Analyst[/font][/size]
May 4, 2009 at 3:06 pm
October 4, 2013 at 4:44 am
Glad you got it working.
Jody Claggett-376930 (5/1/2009)
In an Execute SQL task I have the following configuration:Result Set = Single Row
SQLStatement = SELECT COUNT(ID) AS CheckData FROM Table_A
Compare these in the execution plan.
SELECT COUNT(ID) AS CheckData FROM Table_A
SELECTTOP 1 CAST(ISNULL([Rows], 0) AS Int) CheckData
FROMsys.Partitions P
WHEREP.[Object_ID] = OBJECT_ID('Table_A')
The bigger the table, the faster the second query will be in comparison.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply