Snowflake22
Snowflake22

Reputation: 13

Store a calculated math equation in a Query?

I am working on this:

enter image description here

I would like to know how to create a new column that holds the amount equal to LocalCurrency multiplied by ExchangeRate for each rows of item.

Upvotes: 0

Views: 119

Answers (2)

Deepali Rawat
Deepali Rawat

Reputation: 1

You can calculate when required in a query or can create a view to do so and use it wherever required.

CREATE VIEW Purchase_details AS
SELECT *, localcurrencyamount*exchangerate
FROM your_table_name

Select * from Purchase_details 

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270823

Use a computed column:

alter table t add newcolumn as (localcurrency * exchangerate);

This adds the column to the table so it is calculated automatically when you retrieve it. The value is automatically set so no update is needed.

Upvotes: 1

Related Questions