title: Counting an increase in series with changing parameters for each ID
body: <p>I have an dataset which has 12 different values for an ID, and also start and end Values. What I want to initilize is take the start value as my begining argument of loop and end value as the last argument. Search trough values accourding to them, and finding the first consecutive increase. </p>
  
  <p>Below I posted an example dataset:</p>
  
  <pre><code>create table #sample_data(
  ID  VARCHAR(10), val1 INT, val2 INT, val3 INT, val4 INT, val5 INT, val6 INT, val7 INT, val8 INT, val9 INT, val10 INT, val11 INT, val12 INT, startValue INT, endValue INT  
  );
  
  insert into #sample_data values
      (1001,3,2,1,0,1,2,3,0,0,0,0,0,1,7),
      (1002,1,2,3,4,0,0,0,1,2,3,0,0,1,12),
      (1003,0,3,2,1,0,0,0,0,0,0,0,0,1,12),
      (1004,0,1,2,3,4,0,0,0,0,0,0,0,3,9),
      (1005,1,1,1,1,2,3,2,2,1,1,0,0,1,8);
  </code></pre>
  
  <p>That is the result I expect: 
  for the ID = 1001 my startValue is 1 and end is 7 algorith will go through from val1 to val7 to compare each val with the next one and count an increase till it ends.
  In this case for 1001 it will be be 0 since series will start with a decrease.
  for ID 1002 it will also be 3 (val1 to val4 and it will stop at val5 when a decrease occur)
  for ID 1003 it will be 1 since there is only an increase at the begining
  for ID 1004 it will be 2 since it starts from 3 and ends at val9
  for ID 1005 it will be 2 which is the increase from val4 to val6</p>
  
  <p>I have tried to execute this with writing CURSOR  but since I had more than 300K line of data it took hours to execute. If you have any better suggestion (without using cursor), I will be so thakful.</p>