1

Adding a calculated column is quite easy, but I cant seem to obtain any code for calculating and insert a calculated row.

Now I know that the DB structure is not very good, but it is what it is.

The table looks as follows:

DealerCode  Ratio_ID  Month1   Month2    
000001852   0000428   1752.00  2500.00   
000001852   0000429   0000.00  0000.00   
000001852   0000430   0001.00  0002.00

Now I want to add Ratio_ID 0000431 which adds the 1752.00, 0.00 and 1.00 (Ratio_ID 0000428 0000429 + 0000430) for Month1, and the 2500 for Month2 in the next row.

In other words an additional calculated row would be added as follows: The table looks as follows:

DealerCode  Ratio_ID  Month1   Month2    
000001852   0000431   1751.00  2502.00 

How would I do that?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Herman
  • 157
  • 2
  • 11
  • `Now I want to add Ratio_ID 0000431 which adds the 1752.00, 0.00 and 1.00 for Month1, and the 2500 for Month2 in the next row.` ..Please can you explain it ..not clear – Mudassir Hasan Oct 04 '13 at 09:46
  • 1
    I want to add a calculated row that adds Ratio_ID 0000428 + 0000429 + 0000430 and then calculates a new Ratio_ID 0000431 totalling 1753 for Month1 and 2502 for Month2 – Herman Oct 04 '13 at 09:48
  • Actually several. We have a few hundred dealers across 12 months, and an added row is required for every dealer (and every month). Ie the calculated row would be created for every dealercode. Hope it makes sense. – Herman Oct 04 '13 at 09:57
  • 1
    breaking 3rd NF always makes me angry. What speaks against calculating values for display only? – Najzero Oct 04 '13 at 09:59
  • 1
    You could do this with a INSERT statement and a subselect. It'be something you can only do once as the next time it won't give the desired result as the totals are now a regular row in the table. I would just get the totals by selecting them instead. And yes, fix your table structure. – Edward Oct 04 '13 at 10:00
  • possible duplicate of [Insert into temp values (select.... order by id)](http://stackoverflow.com/questions/263101/insert-into-temp-values-select-order-by-id) – Paul Sweatte Jan 29 '14 at 20:59

0 Answers0