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

Update Field with Value from Another Table

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
I am trying to execute this script but I get an error:

update CUSTREL set PREFSTORE = EMPLOYEE.STORENUM where EMPLOYEE.NUM=CUSTREL.PREFSLSP

Basically I want to update the customer's preferred store location based on the assigned store location of their preferred salesperson. My tables (in a nutshell) are as follows:

CUSTREL
<PrefSlsp>
<PrefStore>

EMPLOYEE
<Num>
<StoreNum>

What script can I use to accomplish this simple task?
 
A few questions:
- What version of PSQL are you using?
- What error do you get?

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Aha - important information.

PSQL v8.

"Unknown table or correlation name (employee)
 
Maybe something like:
update CUSTREL set CUSTREL.PREFSTORE = (select EMPLOYEE.STORENUM where EMPLOYEE.NUM=CUSTREL.PREFSLSP)

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Now I get an error message saying "Column (PrefStore) not nullable". This, to me, indicates one of the following:

- I have a null value in a record for the field EMPLOYEE.STORENUM (I checked and this is not the case)
- I have a value in CUSTREL.PREFSLSP that is not represented in the EMPLOYEE table (perhaps a salesperson was assigned to a customer and that salesperson is no longer with us, thus is not in the EMPLOYEE table)

If the later is true, how can I handle it within the SQL script?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top