i have a select statement that gives me a customerID - and i have some functions in that select statement that use the customerID for various calculations - problem is that each of the functions needs a variable that is provided by 1 function (like LastOrderID), and the nesting of these functions make the stored procedure so slow it eventually times out
What I would like to know is how - in the body of the select statement - how can i run that 1 function 1 time and set the value to a variable so the other functions dont have to run off and keep getting the LastOrderID?
Here is a psuedo-code example of what I am talking about
in the example below:
dbo.fxGetLastOrderAmount uses the OrderID (which is obtained by running dbo.fxGetLastOrderID) to get the Amount of the Last Order
dbo.fxGetLastOrderDate uses the OrderID (which is obtained by running dbo.fxGetLastOrderID) to get the Date of the Last Order
dbo.fxGetLastOrderShipDate
uses the OrderID (which is obtained by running dbo.fxGetLastOrderID) to get the ShipDate of the Last Order
Select CustomerID, CustLastName, CustFirstname, dbo.fxGetLastOrderAmount(d
bo.fxGetLa
stOrderID(
CustomerID
)), dbo.fxGetLastOrderDate(dbo
.fxGetLast
OrderID(Cu
stomerID))
, dbo.fxGetLastOrderShipDate
(dbo.fxGet
LastOrderI
D(Customer
ID)) from Customers
I would like to make the call to dbo.fxGetLastOrderID(Custo
merID) only one time instead of each time for each function - I am not sure when i go get it how i can store it so the other functions can use it
That is a simplistic rendition of what I am trying to do - In reality, there are over 40 columns - 30 of which need the LastOrderID to run the functions - and the functions are much more complicated that what described - I know it is the process of running that function cause when I hard code LastOrderID instead of looking it up each time - the query runs just fine
Start Free Trial