Set Computed Column Specification Or field in Select as sum of child records
Posted on 2007-12-01
I want to set a column in my invoice table to be a sum of the values in my invoice items table using computed column specification.
Example: 3 invoice items with a value of 10 in the total field would make the total field in the invoice table = 30 where the invoice.invoiceid value = the invoice items. invoiceid
If that's not possible how would I do it in my select from the invoice table so that my select returns one row for each invoice but has a column that has a sum of all related invoiceitem.total fields for that invoiceid? Something like:
Select SUM(invoiceitem.total) as total, invoiceid from invoices