|
I have interesting problem but I am not sure if it is even possible to complete. I wanted to see if anyone had any ideas on how to go about this. Please note the example below: This is how I want the data to look. Note at rowno 7 the calculations reverse. Before rowno 7 I add the start and end from the same rowno and carry that value to the start of the nxt rowno. After row 7 it subtracts startrow 7 from end row 8 and puts the value in start of rowno 8.
(comments are locked)
|
|
Is the variance +/- like below, or is it an absolute value? gives The variance is +/- I will probably change it to absolute when graphing.
Nov 01 '11 at 08:18 AM
sqlnewb
@kev riley Would you be able to explain why you used CROSS APPLY? I am trying to learn as many new techniques as I can, but I am a novice at the moment. I have never seen the use of CROSS APPLY
Nov 01 '11 at 08:25 AM
sqlnewb
CROSS APPLY allows me to 'call a function' for each row returned from the base table. The 'function' I'm calling is simply a sum of the values for all the rows prior to the one I'm currently dealing with. This is a case of row-by-agonizing-row (RBAR http://www.sqlservercentral.com/articles/T-SQL/61539/) processing known as a triangular join. It will not perform well on large data sets.
Nov 01 '11 at 08:35 AM
Kev Riley ♦♦
@sqlnewb : updated my answer to correct the error you found.
Nov 01 '11 at 12:34 PM
Kev Riley ♦♦
(comments are locked)
|


Ho do you recognise that RowNo 7 is the end of the group? Is it the zero in the columns Start and End that denote a group of rows?
There is a column with Reasons...the END column is based on variance..SO there is a REASON column that says STATIC when variance is 0
So which column is the 'real' data and which is calculated? Up to
RowNo7 'real' data isEndand after it isStart?@kev Riley END is the variance..S0 it starts at 0 and the first variance is 20 after rowno 7 I just change the order of how the Start column is calculated
So there seems to be 2 separate calculations, depending on whether the variance is before or after the 'Static' value of REASON column (not shown here)?
Is there only ever one 'Static' in the data, i.e. only one turning point?
Could the base data be defined as