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
 New to SQL Server Programming
 Grouping problem

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-09-11 : 17:15:11
Have two tables. Gbkmut, orderrebatehistory

Have 3 entries in the orderrebatehistory where I want to total the rebate amt and insert a record with the total in the gbkmut.

I have the statement to get my calculation, but my trouble is when I insert the record into the gbkmut it is inserting 3 records with my total and not just one.

ORH
Ord_no Inv_no rebate_amt item_no
23 12 1.50 xyz
23 12 2.00 cdd
23 12 3.00 yyy

I want to insert 1 record into the gbkmut with an amoutn fo 6.50.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-11 : 17:26:34
Show us what you have so far, so we can help you with that.

It'll be something like this though:

INSERT INTO...
SELECT ..., SUM(rebate_amt)
FROM SomeTable
GROUP BY ... <-- but not rebate_amt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

pommguest99
Starting Member

16 Posts

Posted - 2008-09-11 : 17:28:34
select Ord_no, sum(rebate_amt) as Total from ORH
group by Ord_no
Go to Top of Page
   

- Advertisement -