Q:

Insert or Update using DataTable in SQL Server

I have the following Stored Procedure to Insert data into a table DataRecord. Now, I have a need to insert or update data. i.e, Insert a record from DataTable into  Table if the Key does not exist - Update the record with the new key if it already exists. I can do this easily when I do it as a single record insert Stored Proc. I'm clueless on how to do it when I send a 100 records in a DataTable.Any help would be appreciated! Thanks!
ALTER PROCEDURE [dbo].[spMultiInsertRecord]  

 (
    @DataTableVar dbo.RecordTableType READONLY
 )  

AS  
BEGIN
    INSERT dbo.DataRecord(Key,KeyType) 
    SELECT Key,KeyType FROM @DataTableVar;
END

A:

You can use the "merge" statement. http://technet.microsoft.com/en-us/library/bb522522%28v=sql.105%29.aspx

