Expression Help

  • I have a field in a data grid that I would like to fill via a simple calculation.  This works fine except when one of the 2 fields I am calculating against is a zero then it returns a value of "Infinity".  What I would like to do is have an expression that applies the calculation but if the second field is 0 then do nothing, or return a blank.  I can do this at the SQL level but I would like to keep all of the applied logic at the report level and keep the SQL query as simple as possible.

  • You should be able to do this with the immediate if function. A statement something like =IIF(TestFields!Value = 0 ,"N/A",Fields.Value/SecondFields.Value)

    The IIF is structured IIF(Test Condition,True Part, False Part), you can also nest these if you need to implement more complex logic.

     

    Stuart

     

  • Keep in mind that RS handles logic at a much slower rate that SQL Server can. If you're not including too much logic, you should be ok. But as you add more, you're reports will take longer to render.

    --Just my two cents.

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Thanks for the code example and the advice on the logic handling.  That did the trick in terms of fixing my problem and I think I will be ok in terms of the amount of logic since I am only calculating a percentage between to columns but as the reports grow I will keep on eye on the rendering time.

  • I was also doing same thing check this link

    http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=150&messageid=297690

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply