Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Load statement
Message
From
01/10/2007 17:47:29
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Load statement
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01257797
Message ID:
01257797
Views:
59
I have two tables: Employee and TempEmployee. TempEmployee comes from another source and has an ID field, and EmployeeID field, and an EmployeeName field. Employee has those same fields plus a ScreenOrder field.

I want to come up with a statement that will insert the record into Employee if it doesn't already exist but does exist in TempEmployee as keyed by EmployeeID. I want the ScreenOrder field to always be the maximum value + 1.

I can show the records like so:
SELECT * FROM TempEmployee WHERE EmployeeID NOT IN (SELECT EmployeeID FROM Employee)
but I don't know how to insert those records into Employee without creating a temporary table and looping through it. Is there an easy way I don't know about?

Thanks!

(Sorry about the thread title - I forgot to rename it to something descriptive after I typed the message)
Very fitting: http://xkcd.com/386/
Next
Reply
Map
View

Click here to load this message in the networking platform