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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mass update one table from a second table

Status
Not open for further replies.

NCYankee1

Programmer
Mar 27, 2001
66
0
0
US
I have two tables:

tblA
===============
CustNbr int
SeqNbr int
Field1 varchar
Field2 varchar

tblB
================
CustNbr int
SeqNbr int
FieldX varchar

I want to update Field2 in tblA with the values from FieldX in tblB where tblA.CustNbr=tblB.CustNbr and tblA.seqnbr=tblB.seqNbr.

When I try:
update tblA set Field2=(select b.FieldX from tblB b inner join tblA a on b.CustNbr=a.CustNbr and b.SeqNbr=A.SeqNbr)

I get a message saying "subquery returned more than 1 value...". How do I set up my SQL statement to whip successfully do this update?

Thanks!



 
Lots of people get this confused. The syntax should be...

Code:
Update tblA
Set    tblA.Field2 = tblB.Fieldx
From   tblA
       Inner Join tblB
         On  tblA.CustNbr = tblB.CustNbr
         And tblA.SeqNbr = tblB.SeqNbr



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That's the ticket! Man, what a mental block I had. Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top