Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2004-11-24 : 15:00:52
|
I'm using an expressional condition in one of my field, and I kept getting this error. "Attempted to divide by zero."Here's what my condition:=iif( Fields!ORDER_AMT.Value = 0, "N/A", Round((Fields!EST_COST.Value)/( Fields!ORDER_AMT.Value) * 100, 2))I'm trying to do some calculation if the Order amount is not zero. Otherwise it should not do the calculation and give "N/A" instead of the #ERROR that I get when it trys to divide by zero. Somehow it doesn't seem to see that. Any suggestions? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-24 : 15:10:04
|
I've noticed that RS actually checks the false part of the IIF. So it's evaluating it even though it wouldn't have displayed it. I think this is a bug. At least it should be. I've had to do some workarounds to get this type of thing to work for us.Tara |
 |
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2004-11-24 : 15:33:10
|
Tara,What's the workaround that you did to get it working? It will only works if I use like a phrase for the expression.=iif( Fields!ORDER_AMT.Value = 0, "N/A", "YEA")That seems to work, but the calculation doesn't seem to be working. Not sure if I need to do a custom coding and have it do it that way. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-11-24 : 15:34:38
|
You could add custom code to the report to fix this. So in the false part, call the custom function which will handle what to do.Tara |
 |
|
jhermiz
3564 Posts |
Posted - 2004-11-25 : 00:55:31
|
You can also make that false portion a calculated field and then reference it. |
 |
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2004-11-30 : 12:20:57
|
Thanks. Creating the calculated field works, but I still get an error at the bottom saying attempting to divide by zero. I do get the result. I do get the result that I wanted though. Not sure if the error I get down by the task pane makes any difference. |
 |
|
|
|
|