![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
On 14 Feb., 22:28, "el" <eldrickva... (AT) hotmail (DOT) com> wrote: 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 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 --- |
#4
| |||
| |||
|
|
On Feb 15, 2:08 am, "Jens" <J... (AT) sqlserver2005 (DOT) de> wrote: On 14 Feb., 22:28, "el" <eldrickva... (AT) hotmail (DOT) com> wrote: 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 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 --- 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- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |