Hello,
I have a stored procedure that makes very complex joins and returns 1 row of data (LIMIT 1 is used). In my application I then use that data to make some calculations. This way I try to keep business logic out of stored procedures. But now I need to get that data in another stored function to also make some calculations. The reason I want to create the stored function is because it will be called in another query that returs thousands of rows.
Is it possible? I don't want to duplicate complex join logic in the stored function... The only solution I see is to use output parameters.
-----------------------------------
PS. I decided to explain you my situation, maybe you will offer me another decision.
I need to calculate delivery duty paid price (it's final price, including packaging, delivering and customs clearance) of the goods. The calculation of this delivery duty paid price is a bit complex, and I don't want to keep complex logic in my stored procedures and functions. So I created a stored procedure that selects all the data necessary to make the calculation of the price and I use that data in my application to calculate the price. For now everything works good.
But now I need to create a price-list with delivery duty paid prices and we have thousands of goods. So if I call my stored procedure for every peace of goods it will take thousands of round-trips (queries) to the server. That is why I want to create a function that will call the stored procedure and calculate the price based on returned data. And then I want to use it like this:
SELECT Description, blablabla, Weight, ..., GetDeliveryDutyPaidPrice(...) FROM pricelist;
Any ideas?