Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Compare records in two tables

Author  Topic 

swordfish8
Starting Member

1 Post

Posted - 2012-05-31 : 17:25:59
Hi there

My requirment is to import contacts into our SQL Database through ASP.NET application.

XL File are used to import contacts through the ASP.NET application all the records from the xl file are inserted into the table Temp_Contacts

Then I want to compare records in Temp_Contact table with the records in the Staff table, To determine if its an Insert or Update.

Fields in Temp_Contact table
SiteID, ContactTypeID,FirstName, LastName, Designation, Mobile, Phone, email, StaffID = 0

Fields in Staff table
StaffID, SiteID, ContactTypeID,FirstName, LastName, Designation, Mobile, Phone, email

I need a SQL query to determine if the records are to be updated or inserted.

Please help.




Sword

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-31 : 18:03:45
use MERGE

http://www.bidn.com/blogs/bretupdegraff/bidn-blog/239/using-the-new-tsql-merge-statement-with-sql-server-2008

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -