sql server - Adding and multiplying tables' data by values in another table -


Say I have a table of sort lines and divisions according to the date:

  tblFactors dt Sub Divide 2014-07-01 1 1 2014-06-01 0 5 2014-05-01 2 1 2014-05-01 0 3 I have one of the ordered values ​​according to the date And the essence is:  
  tblValues ​​DT Val 2014-07-05 4 2014-06-15 5 2014-05-15 21 2014-04-14 31 2014-03-15 71 < / Code> 

I need to do some sequential calculation for the first value in I tblFactors , I would have to deduct 1 from each val where tblValues.dt & lt; '2014-07-01'.

Next, I need to process the second row in tblFactors I subtract nothing. However, divided = 5 means that I Each val needs to be divided by 5 where tblValues.dt & lt; '2014-06-01'. The hard thing is that I need to split it on the modified wall (not the 20/5, 21/5) from the first row.

Void subtraction 1 divided by 5 minus 2 divide 3 7/5/2014 4 6 / 15/2014 5 4/15/15 21 21 4 4/14/2014 31 30 6 4 3/25/2014 71 70 14 12 4

This will leave me:

  qryValues ​​DT Val 2014-07-05 4 2014-06-15 4 2014-05-15 4 2014 -04-14 4 2014-03-15 4  

Right now I am increasing the vector times on the loop in R . I was thinking that there is a smart way to accomplish this in the original SQL. I tried to do some aggregation, but I got limited success.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -