Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Add calculated field

Author  Topic 

drmohamedbekheit
Starting Member

5 Posts

Posted - 2014-11-21 : 02:34:46
Dear All
In my DB, I have two coolumns of interest to this query (hemo and Volume).
I would like to add to the hemo table couple of columns that is calculated from field in the volume table and field from hemo table.

The new field named (pressure_mass_unit) = (portal_pressure) from hemo*100 / (residual_volume) from volume table.

I imagine that this would contain a subquery with select, but I do not know

Best

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-21 : 09:25:20
Create a scalar UDF that takes in one value (don't know if they are integers, floats or decimal, but I guess you know!) and returns the product. The UDF will have to get the other value from the volume_table, to do the multiplication.

Alter your table like this:


alter table hemo
add computed_col as dbo.compute_func (hemo)
Go to Top of Page
   

- Advertisement -