I need to merge 24 functions into 1

  • Hi ,

    I have a really strange file. I will use an example to explain. The files has many records. The fields are customer_no, price_01, price_02, price_03 up to price_24.

    The prices (price_01, price_02, etc...) are basic prices. There is a long program to calculate the final price. The previous programmer wrote 24 functions !!! So, if the formula to calculate the price change, I have to go in 24 functions...

    What I'm trying to do is to pass 01, 02, 03, etc... and the functions will pick the fields in the database using price_ and the value.

    I would like to know if you have an idea how to do it ?

    Thanks

    Real

    real@paromail.com

  • need more detail;

    is there 24 different formulas, one for each column in your customer table, or is it the same calculation, but placed in 24 functions? show us two of the functions, say the one for column 1 and the next for column 2. we can compare them, see if they are doing the same thing, and work out some examples with that.

    the devil is in the details...without giving us details, all we can do is speculate.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • You understand the problem very well. The formulas are all the same in the 24 functions. The only thing that differ is the fields (price_01, 02, 03, etc).

    Thanks

    Real

  • real (4/21/2009)


    You understand the problem very well. The formulas are all the same in the 24 functions. The only thing that differ is the fields (price_01, 02, 03, etc).

    Thanks

    Real

    Awesome! Now, we still need to see the code.

  • It's something like this

    Declare @price decimal(10,2)

    SET @price = price_01 FROM prices

    SET @rebate = rebate_01 FROM rebates

    SET @shipping = shipping_01 FROM Shipping

    With "hundred" of formulas.

    .

    .

    .

    As you can see, only the 01 change. I would like to create only one function. Only the 01, 02, are changing

    Thanks

    Real

  • kewl; once you post the actual functions, we'll be able to help; offhand, it looks like it could be replaced with a view that joins all your columns with joins to price, rebate and shipping tables, doing the calulations in the view for your actual costs instead, and getting rid of the functions altogether.

    remember pseudo code can help explain the problem, but if you want a complex answer, throw out the pseudo code and give us the actual CREATE FUNCTION scripts.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • real (4/21/2009)


    It's something like this

    Declare @price decimal(10,2)

    SET @price = price_01 FROM prices

    SET @rebate = rebate_01 FROM rebates

    SET @shipping = shipping_01 FROM Shipping

    With "hundred" of formulas.

    .

    .

    .

    As you can see, only the 01 change. I would like to create only one function. Only the 01, 02, are changing

    Thanks

    Real

    For the best help, read and follow the guidelines in this article: Forum Etiquette: How to post data/code on a forum to get the best help[/url].

    For why you should, read this blog: The Flip Side.

Viewing 7 posts - 1 through 7 (of 7 total)

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