getting error when i use merge statement
Try using the keywords TARGET and SOURCE. 

MERGE products AS target
  USING updatedproducts AS source
  ON (target.productid = source.productid)
  WHEN MATCHED and target.productname &lt;&gt; source.productname OR
    target.rate &lt;&gt; source.rate
    THEN UPDATE
     SET
      target.productname = source.productname
     ,target.rate = source.rate
  WHEN NOT MATCHED BY TARGET 
    THEN INSERT
      (productid
      ,productname
      ,rate)
     VALUES
      (source.productid
      ,source.productname
      ,source.rate)
  WHEN NOT MATCHED BY SOURCE 
    THEN DELETE
  OUTPUT
    $action
   ,deleted.productid AS trgtproductid
   ,deleted.productname AS trgtproductname
   ,deleted.rate AS trgtrate
   ,inserted.productid AS srcproductid
   ,inserted.productname AS srcproductname
   ,inserted.rate AS srcrate;
SELECT
  @@rowcount;


Should work like a charm