Answered by:
Constraint Expression Dividebyzero error
Question

I am trying to put a precedence constraint based on the percent of error rows in a data flow task. Two variables, @ErrorRowCount and @ExtractRowCount, are assigned values in the dataflow. When I try to enter the expression @ExtractRowCount==0 ? False : @ErrorRowCount / @ExtractRowCount < .05 I get the error A dividebyzero error occured. The right side operand evaluates to zero in the expression "@ErrorRowCount / @ExtractRowCount".
I can work around the problem by assigning a nonzero value to the ExtractRowCount at design time, and it appears the expression evaluates as expected when @ExtractRowCount is 0 at runtime. Is there a way to accomplish this in the SSIS expression language without assigning an arbitrary value to my variable?
Answers
All replies

Your expression is not working like you expect. This is how SSIS is evaluating the expression you wrote:
((((@ExtractRowCount == 0) ? False : @ErrorRowCount) / @ExtractRowCount) < .05)
Your expression is always dividing by @ExtractRowCount  which I know you don't want! Surround your "false" clause with parentheses. 
I may have omitted the quotes in my original question, but I just tried each of the following:
@ExtractRowCount==0 ? FALSE : (@ErrorRowCount / @ExtractRowCount < .05)
@ExtractRowCount==0 ? FALSE : ((@ErrorRowCount / @ExtractRowCount) < .05)
(@ExtractRowCount==0) ? FALSE : (@ErrorRowCount / @ExtractRowCount < .05)
(@ExtractRowCount==0) ? FALSE : ((@ErrorRowCount / @ExtractRowCount) < .05)
((@ExtractRowCount==0) ? FALSE : ((@ErrorRowCount / @ExtractRowCount) < .05))
All generate the identical error message: A dividebyzero error occured. The right side operand evaluates to zero in the expression "@ErrorRowCount / @ExtractRowCount". 


You shouldn't need to do that. I'm surprised the precedence condition's expression does that  but if it does, it does. You can add an SSIS boolean variable and place that expression inside it, then use that variable in your precedence constraint condition. I'm certain I've done expressions with protection for division by zero and it functioned...