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

update syntax 2

Status
Not open for further replies.

CRuser89

Programmer
May 18, 2005
79
US
hello,

I am very new to sql server. I've been programming in oracle so I know that sql server syntax is quite different. Can you please tell me if my update statement below has the correct syntax?

Thanks in advance

UPDATE employee
SET employee.id = personnel.id
FROM employee, personnel
WHERE employee.primaryKey = personnel.foreignKey

Also, can you please tell me how to set employee.id equal to the last 2 digits of the personnel id?

Thanks,
 
Shouldn't the ON part also use the table aliases?

Code:
UPDATE e
SET e.id  = RIGHT(p.id,2)
FROM employee e 
JOIN personnel p
ON [!]e[/!].primaryKey = [!]p[/!].foreignKey

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
so here are 2 ways, the first one with aliases, the second one with out and also the old join syntax
Code:
UPDATE e
SET e.id  = RIGHT(p.id,2)
FROM employee e 
JOIN personnel p
ON e.primaryKey = p.foreignKey

UPDATE employee
SET employee.id  = RIGHT(personnel.id,2)
FROM employee, personnel
WHERE employee.primaryKey = personnel.foreignKey

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top