15,947,958 members
See more:
plz can anybody help me i have the one table eg tbl_1 and i have column eg A B C
when i insert into column A and B its result store into C like c=a-b
Posted
phil.o 28-Sep-15 16:30pm
What have you tried?
Moreover, it is not really clear what you want to achieve.
Do you want to do an arithmetic operation in your INSERT statement?
Or do you want a computed column? (a computed column is a column which automatically computes the result of a given operation)
Member 11963532 28-Sep-15 16:39pm
i have table with field product_price,Advance_income and i have last field name remaing_income i want now here when i insert the value into column product_price and advance_income in the remaing income the result will show between two diffrent values for example
if i put the value in product_price 9000 and i put in advance 1000 then remaing income column insert the value automatically 8000

## Solution 2

This could be done in several ways. You could define a trigger making the calculation and storing the result or you could not store the result at all but create a view which would do the calculation. But perhaps the simplest solution would be to use a computed column.

Consider the following
SQL
```CREATE TABLE CalcTest (
A int,
B int,
C AS A-B
);

INSERT INTO CalcTest (A, B) VALUES (2,1);
INSERT INTO CalcTest (A, B) VALUES (1,1);
INSERT INTO CalcTest (A, B) VALUES (1,2);
INSERT INTO CalcTest (A, B) VALUES (NULL,1);
INSERT INTO CalcTest (A, B) VALUES (1,NULL);
INSERT INTO CalcTest (A, B) VALUES (NULL,NULL);

SELECT * FROM CalcTest;```

The result of the SELECT query would be
```A      B      C
----   ----   ----
2      1      1
1      1      0
1      2      -1
NULL   1      NULL
1      NULL   NULL
NULL   NULL   NULL```

Member 11963532 28-Sep-15 16:54pm
thank you so much Mika Wendelius this is really helpfull thnxx lott again....
Wendelius 28-Sep-15 17:03pm