SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Compare records in two tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

swordfish8
Starting Member

New Zealand
1 Posts

Posted - 05/31/2012 :  17:25:59  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 05/31/2012 :  18:03:45  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000