getting error when i use merge statement I am using sql 2008 r2. when i use merge statement i am gettig error
when i execute following code: 

merge products as trgt
using updatedproducts as src 
      on (trgt.productid = src.productid) 
when matched and trgt.productname &lt;&gt; src.productname or trgt.rate &lt;&gt; src.rate then 
     update set trgt.productname = src.productname, 
     trgt.rate = src.rate 
when not matched by trgt then 
     insert (productid, productname, rate) values (src.productid, src.productname, src.rate)
when not matched by src 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;
go


I am getting error like this: 

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'as'.


Why am i getting this error?
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