Solved

Set Computed Column Specification Or field in Select as sum of child records

Posted on 2007-12-01
3
1,893 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:advlgx
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 20388390
>>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. <<
No that is not possible.  You could do it with a Select statement and a Group clause.  But without knowing the table structure it is difficult to be precise.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 20388396
Here is another option using a subquery:

Select Col1, Col2, Col3,
           (Select SUM(Total) From invoiceitem Where invoiceid = i.invoiceid)
From   invoice i
0
 

Author Closing Comment

by:advlgx
ID: 31412099
Thanks!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now