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

sql update script

Status
Not open for further replies.
Nov 12, 2003
22
GB
on a test dataset i have created a tbl (testaddress) containing two fields Client_Ref and AddLocality from another table (CR_Clients). I have updated the addlocality values in CR_CLIENTS to Null and now i am trying to put the addlocality back into CR_CLIENTS using the stored data in TestAddress. I am using the following SQL and getting an error. what am i doing wrong?


UPDATE CR_CLIENTS
SET CR_CLIENTS.addlocality = TESTADDRESS.addlocality
WHERE CR_CLIENTS.Client_Ref = TESTADDRESS.Client_Ref


Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'TestAddress' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'TestAddress' does not match with a table name or alias name used in the query.

 
This will update records, so it is ALWAYS a good idea to backup data before performing this type of operation.

Code:
UPDATE CR_CLIENTS
SET CR_CLIENTS.addlocality = TESTADDRESS.addlocality
From CR_CLIENTS
     Inner Join TESTADDRESS 
       On CR_CLIENTS.Client_Ref = TESTADDRESS.Client_Ref

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You'd be surprised how often this comes up. Especially since Microsoft Access's syntax (to accomplish the same thing) is different.

I'm glad this worked for you.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top