Sum the same?

sasolini

Registered User.
Local time
Today, 22:15
Joined
Dec 27, 2004
Messages
61
Hey,

I have a big problem, becouse i even dont know where to start this time? :confused:

Ok, for the start i have a Table1 and Table2 with fields (ID, TIP, DN, Pieces, Date).
What i need is to run thrue the records in Table1 and select the records with the same TIP and DN and than sum the Pieces together and send that data to Table2. This should be done automaticaly with no interfirenc of users.

I hope youll understand what i mean...

Thx
 
Do you mean someting like


Code:
INSERT INTO table2 ( SumOfpieces )
SELECT Sum(Table1.pieces) AS SumOfpieces
FROM Table1
WHERE (((Table1.tip)=[Table1.dn]));
 
THX this works great!

The only think is that other this code "copy" only the peaces, but i would need to copy all the fields (TIP; DN, DATE). Can you pls tell me how to modify that code of yours to work that way?

And one more think...Is it posible to count the same records, just the way u did now and simply just count and paste the peaces in new table?

Thx !!!
 
Ok what you want to do is create a table identical to table1 but instead of multi rows of identical TIP DN DATE(BTW NEVER use Date as a field name it is an Access reserved word and function), but to continue, and Sumof pieces ?

Code:
INSERT INTO table2 ( SumOfpieces, tip, dn, [date] )
SELECT Sum(Table1.pieces) AS SumOfpieces, Table1.tip, Table1.dn, Table1.date
FROM Table1
WHERE (((Table1.tip)=[Table1.dn]))
GROUP BY Table1.tip, Table1.dn, Table1.date;


Brian
 
hmm that was one part of my question ;)

But still i have a problem:

If i use WHERE (((Table1.Tip)="A") AND ((Table1.DN)=15)) the code is ok, but as you can see thats criteri based on one record, thats why i get only one records in Table2, and thats not what i want.

If I use your code WHERE (((Table1.tip)=[Table1.dn])) i get err "Data type mismatch in criteria expression." ?


The second part of my question is if its posible to count records based on the same cryteria that i need now, but if they dont have field "Pieces" insted one record is +1 fo SumOfpices? Becouse i would need that for somethink else if its posible?

Thx for helping!!!
 
What i need is to run thrue the records in Table1 and select the records with the same TIP and DN


If i use WHERE (((Table1.Tip)="A") AND ((Table1.DN)=15)) the code is ok, but as you can see thats criteri based on one record, thats why i get only one records in Table2, and thats not what i want

:confused: :confused: :confused: :confused:

I guess I don't understand the requirement, and unfortunately as this is my last day in before going on holiday I wont have the time to follow up.

Hope somebody else picks this up for you.

Brian
 
no swet;)

I get it..the problem was in WHERE (((Table1.tip)=[Table1.dn])) it should be WHERE (((Table1.tip)=[Table1.tip]))

And the other think...I solve it some other way!

Happy Hollidays man!!! THX!!!
 

Users who are viewing this thread

Back
Top Bottom