Mathematical Operation

  • Hi,

    I need to write a stored proc that takes a set of input parameters and then performs mathematical operation referencing several other lookup tables and interim calculation results.

    The set of input comes from a table - so I need to process all rows in the input table.

    Will a while loop \ cursor be recommended for this type of operation or not at all?

    The other option then will be to have several temp tables - as output from joining the lookup tables?

    Please advise!

    Thanks,

  • A lot depends on whether the mathematical operations needed can be performed by queries using aggregates, joins the apply operator, and so on. On what you've told us, there's nothing that says it can't be done with a single SQL statement and equally nothing that says it can be done with multiple operations and loops. As a general rule, it's a good idea to try to aoid using explicity loops (and of course explicit cursors) but there are a few cases where the general rule doesn't actually fit (usually where someone has the schema design screwed up, but some real cases too).

    Tom

  • Hi Tom,

    As I mentioned there are several tables to join and one calculation feeds another table \ calculation.

    So IMO (if possible) doing all that in one SQL will make it a ugly looking SQL.

    Breaking it down in multiple lines is ideal from the readability \ maintenance of the calculation.

    Cheers,

    Bikram

  • Pretty sure Tom got the high level description. The problem is - it's so generic, we have no way to provide you with advice on how to implement. Hopefully there is a way to provide SOME detail, enough to point us to that general idea, but keep enough back so you can still protect whatever idea you are trying to build.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

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

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