Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update record multiple fields

Status
Not open for further replies.

jvande

MIS
Jun 6, 2001
115
US
What is the best way to update multiple fields in a record?
Table1
Field1 -primary key
Field2
Field3
Field4
Field5

Insert into Table1 t1 (field1,Field3,Field4,Field5) (select field1,sum(field3),sum(field4),sum(field5) from table2 t2 group by field1) where t1.field1=t2.field1

I know that doesn't work because it says the field1 already exists. But that is the psuedo code that I am trying to accomplish.
 
This should do what you need:

Update Table1
Set Field3 = t2.SumField3,
Field4 = t2.SumField4,
Field5 = t2.SumField5
FROM Table1 t1
INNER JOIN (Select Field1, sum(field3) as SumField3, sum(field4) as SumField4, sum(field5) as SumField5 from table2 group by field1) t2
ON t1.Field1 = t2.Field1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top