dbTalk Databases Forums  

updating an sql table using another sql table

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss updating an sql table using another sql table in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
el
 
Posts: n/a

Default updating an sql table using another sql table - 02-14-2007 , 03:28 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


Reply With Quote
  #2  
Old   
Jens
 
Posts: n/a

Default Re: updating an sql table using another sql table - 02-15-2007 , 02:08 AM






On 14 Feb., 22:28, "el" <eldrickva... (AT) hotmail (DOT) com> wrote:
Quote:
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
---



Reply With Quote
  #3  
Old   
el
 
Posts: n/a

Default Re: updating an sql table using another sql table - 02-15-2007 , 09:09 AM



On Feb 15, 2:08 am, "Jens" <J... (AT) sqlserver2005 (DOT) de> wrote:
Quote:
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



Reply With Quote
  #4  
Old   
el
 
Posts: n/a

Default Re: updating an sql table using another sql table - 02-15-2007 , 09:26 AM



On Feb 15, 9:09 am, "el" <eldrickva... (AT) hotmail (DOT) com> wrote:
Quote:
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 -
I figured out my problem. It worked perfectly. Thank you for the
assistance.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.