Groups | Blog | Home
all groups > sql server clients > february 2007 >

sql server clients : updating an sql table using another sql table


el
2/14/2007 1:28:29 PM
I started with a CSV file which I imported into SQL to create a table.
My initial table is employees (ID, LastName, FirstName, Department,
Division, Title, OfficePhone, MobilePhone, Login). The new table is
called employees_update ( LastName, FirstName, Login, OfficePhone).
I need to update the employees table (374 records) with the info in
the employees_update table (193 records).
I need SQL to:
1. Update the records in the employees table from the
employees_update table
2. Insert new records into the employees table from the
employees_update table
Jens
2/15/2007 12:08:07 AM
[quoted text, click to view]

UPDATE employees
SET Col1 = A.Col1 (Rest of the Update goes here)
FROM employees
INNER JOIN employees_Update A
ON employees.YourPK = A.YourPK

And so the insert

INSERT INTO employees
(ColumnListHere)
SELECT
columnlisthere
FROM employees_Update
WHERE NOT EXISTS
(
SELECT * FROM employees WHERE employees.YourPK =
employees_Update.YOurPK
)

HTH, Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---
el
2/15/2007 7:09:45 AM
[quoted text, click to view]

I was able to get the update to work but the insert is giving me the
error:
Server: Msg 2809, Level 18, State 1, Line 1
The request for procedure 'Employees' failed because 'Employees' is a
table object

The line is INSERT INTO Employees
el
2/15/2007 7:26:35 AM
[quoted text, click to view]

I figured out my problem. It worked perfectly. Thank you for the
assistance.

AddThis Social Bookmark Button