Advertisement

05.19.2007 at 04:04PM PDT, ID: 22582881
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

nested function calls slowing stored procedure causing it to time out - how to use a function in a select stmt to populate a variable

Asked by bigbillydotcom in MS SQL Server

Tags: , , , ,

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(dbo.fxGetLastOrderID(CustomerID)), dbo.fxGetLastOrderDate(dbo.fxGetLastOrderID(CustomerID)), dbo.fxGetLastOrderShipDate(dbo.fxGetLastOrderID(CustomerID)) from Customers

I would like to make the call to dbo.fxGetLastOrderID(CustomerID) 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
 
 
[+][-]05.19.2007 at 05:30PM PDT, ID: 19121788

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2007 at 06:07PM PDT, ID: 19121891

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2007 at 07:21PM PDT, ID: 19124836

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: nested, procedure, function, stored, call
Sign Up Now!
Solution Provided By: James0628
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43