I´m trying to sum all values from various id with a condition in a SQL server database.
i can do it with a select to an fno and one type of tabiva, but when try to do the update i can´t.
I try and search, but is always giving me error.
Table 1
|fno|TABIVA|VATTOTAL|
|100| 1 | 1.35 |
|100| 1 | 2.00 |
|100| 3 | 1.50 |
|200| 2 | 4.00 |
|300| 1 | 3.00 |
|400| 3 | 1.50 |
|400| 2 | 2.00 |
|400| 1 | 1.20 |
Table 2
|fno|TABIVA1|TABIVA2|TABIVA3|
|100| 0.00 | 0.00 | 0.00 |
|200| 0.00 | 0.00 | 0.00 |
|300| 0.00 | 0.00 | 0.00 |
|400| 0.00 | 0.00 | 0.00 |
Result expected after the update on table 2
|fno|TABIVA1|TABIVA2|TABIVA3|
|100| 3.35 | 0.00 | 1.50 |
|200| 0.00 | 1.50 | 0.00 |
|300| 3.00 | 0.00 | 0.00 |
|400| 1.20 | 2.00 | 1.50 |