It's one of the good features of sql server 2008,check the below syntax for merger
MERGE #temp AS t
USING #temp1 AS t1
ON t.ID = t1. ID
WHEN MATCHED THEN
UPDATE SET C.Colname= NC.Colname
WHEN NOT MATCHED THEN
INSERT (ColName, ColName1) VALUES (NC.ColName1,NC.ColName1);
in place of #temp1 you can also have select statement with parameters that you need to insert into #temp.
Based on the matching condition it will update or insert records.