Re: acculated calculations
Posted in 1995
>From: tangh@cc.memphis.edu >Date: 30 Aug 95 15:50:33 -0500 >X-Informix-List-Id: <news.16674> > >Hello, everyone. I need to perform an procedure in a report to get an >accumlated result. The table layout is as following: > >col1 col2 col3 >1 2% 2% >3 4% (1*2% + 3*4%)/(1+3) >5 6% (1*2% + 3*4% + 5*6%)/(1+3+5) >7 8% (1*2% + 3*4% + 5*6% + 7*8%)/(1+3+5+7) > >col3 involves the calculations from col1 and col2. What is the best way to >write this report? Should I use a cursor or stored procedure? Could someone >give me some point how to do this? Thanks. Tina. This seems to be very straight-forward in plain ISQL ACE -- adapt the report below to I4GL as required. I'm using Systables(Tabid, Rowsize) as the data source with OnLine 6.00.UE1; it'll work with any version but you may get slightly different numerical answers depending on how many system tables you actually have. The first three columns are the answer you want; the remainder are debugging information so you (and I) can see whether the answer is plausible. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> PS: I got only 3 decimal places in the output because I should have used char(20) instead of char(15). Report: database stores end define variable n1 integer variable n2 integer variable n3 decimal variable fm char(15) end select tabid col1, rowsize col2 from systables order by col1, col2 end format first page header let n1 = 1 let n2 = 1 let n3 = 0 let fm = "##########&.&&&&&&&&" on every row let n3 = n3 + n1 * col2 print col1, col2, (n3 / n2) using fm, n1, n2, n3 using fm let n1 = n1 + 2 let n2 = n2 + n1 end Output: 1 104 104.000 1 1 104.000 2 36 53.000 3 4 212.000 3 78 66.889 5 9 602.000 4 28 49.875 7 16 798.000 5 25 40.920 9 25 1023.000 6 70 49.806 11 36 1793.000 7 19 41.633 13 49 2040.000 8 10 34.219 15 64 2190.000 9 34 34.173 17 81 2768.000 10 70 40.980 19 100 4098.000 11 53 43.066 21 121 5211.000 12 16 38.743 23 144 5579.000 13 39 38.781 25 169 6554.000 14 263 69.668 27 196 13655.000 15 10 61.978 29 225 13945.000 16 51 60.648 31 256 15526.000 17 265 83.983 33 289 24271.000 18 277 104.833 35 324 33966.000 19 21 96.241 37 361 34743.000 20 25 89.295 39 400 35718.000 21 98 90.104 41 441 39736.000 22 72 88.496 43 484 42832.000 23 265 103.510 45 529 54757.000 24 279 117.830 47 576 67870.000 99 0 108.592 49 625 67870.000 100 134 110.509 51 676 74704.000 101 80 108.291 53 729 78944.000 102 18 101.957 55 784 79934.000 103 43 97.961 57 841 82385.000 104 17 92.653 59 900 83388.000 105 21 88.105 61 961 84669.000 106 517 114.492 63 1024 117240.000 107 78 112.314 65 1089 122310.000 108 143 114.093 67 1156 131891.000 109 65 111.327 69 1225 136376.000 110 377 125.882 71 1296 163143.000