Loading ...

Help with INSERT statement

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » Help with INSERT statement

Help with INSERT statement

Posts under the topic: Help with INSERT statement

Posted: 7/5/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51

I am trying to insert the SUM of a column from one table into a field of a different table.

 

INSERT INTO [ChangeDue] ([PatmentAmount], [TotalDue]) VALUES (@PatmentAmount,@TotalDue)


ToatlDue   is actually the SUM of a column called ItemTotal from my Receipts TABLE. How can I do that?

 

thanks in advance


Posted: 7/5/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74
  Answered

Hi Mike,

Use SELECT statement to get totals, like this

INSERT INTO [ChangeDue]([PatmentAmount],[TotalSum])
SELECT [PatmentAmount], SUM([ItemTotal]) as [TotalSum]
FROM [Receipts]
GROUP BY PatmentAmount;

Best Regards,

Gjorgji


tags Sql
Page 1 of 1 (2 items)