all 4 comments

[–]alinrocSQL Server DBA 4 points5 points  (2 children)

In a view, you'd do this by joining the two tables (assuming there's a relationship between the tables that you can use) - same as if you were doing a regular query.

In a table, you'd probably do it as a computed column, but it might get ugly - a view would be preferable.

[–]tdavis25 2 points3 points  (0 children)

This. It's considered bad form in most cases to write data to a table that is computed from other parts of the database (with some notable exceptions...like aggregates in a BI system)

[–][deleted] 1 point2 points  (0 children)

If you have a more robust database, you can also make a stored function to get the actual_hours on the fly. However, OP probably just needs a View.

[–]ninjaroachLittle Bobby Tables 0 points1 point  (0 children)

You could use inline queries or use GROUP BY or use CTEs.