title: Should I create a stored function/procedure or keep the query?
body: <p>This may be the wrong spot to ask this question so please forgive me if it is.</p>
  
  <p>So I have a DB2 query that is 400 lines long but it does quite a few separate calculations to determine if a customer is profitable or not with their LTL shipments by lane and by terminal/delivery location.</p>
  
  <p>My question is generally speaking would it be faster to continue to do this in a query form or pass some of the algorithm through a stored function? It is running the OR report by line item so there could be thousands of lines/bills per customer for any given time period.</p>
  
  <p>I guess I am just looking for some advice from you beautiful people that have a different perspective or more experience than me.</p>
  
  <p>Thanks.</p>
  
  <p>--EDIT--
  I am trying to increase speed, when I run it for 1 customer its fast enough but when I run it company wide it takes about a half hour for a month of data(roughly 40k bills).<br>
  It really only deals with 4 tables, mostly just calls for 1 column of data. At its widest point its about 40 columns wide, but that could be condensed, i just like to be able to see the calculations in line before they are combined and summed up in a cleaner format. I do make use of a With Loop as() and then just mine that temp table for the final output.</p>