Posts Tagged ‘merge’

;MERGE RUO_ITEM AS rsRUO
USING @ruoItems AS updatedRUO
ON (rsRUO .FieldId = updatedRUO.FieldId )
 
WHEN MATCHED THEN
UPDATE
SET
      rsRUO .EntityType = updatedRUO.EntityType ,
      rsRUO .MasterEntityTypeId = updatedRUO.MasterEntityTypeId ,
      rsRUO .FieldValue = updatedRUO.FieldValue ,
      rsRUO .RetailElementId = updatedRUO.RetailElementId ,
      rsRUO .FieldName = updatedRUO.FieldName ,
      rsRUO .ValueSeq = updatedRUO.ValueSeq ,
      rsRUO .CreateDatetime = updatedRUO.CreateDatetime ,
      rsRUO .ChangedDatetime = updatedRUO.ChangedDatetime ,
      rsRUO .RowStatus = updatedRUO.RowStatus ,
      rsRUO .ChangedById = updatedRUO.ChangedById
 
WHEN NOT MATCHED THEN
INSERT (EntityType ,EntityTypeId, MasterEntityTypeId,RowSeq , RetailElementId,FieldValue, FieldName,ValueSeq , CreateDatetime,ChangedDatetime, RowStatus,ChangedById )
VALUES(updatedRUO .EntityType, updatedRUO.EntityTypeId ,updatedRUO. MasterEntityTypeId,updatedRUO .RowSeq, updatedRUO.RetailElementId, updatedRUO.FieldValue ,updatedRUO. FieldName,updatedRUO .ValueSeq, updatedRUO.CreateDatetime, updatedRUO.ChangedDatetime ,updatedRUO. RowStatus,updatedRUO .ChangedById)
output
            inserted .EntityType,     
            inserted .EntityTypeId,     
            inserted .RowSeq,    
            inserted .RetailElementId ,    
            inserted .FieldValue ,     
            inserted .FieldName ,     
            inserted .ValueSeq ,     
            inserted .CreateDatetime ,     
            inserted .ChangedDatetime ,    
            inserted .RowStatus,
            inserted .ChangedById
 into @tmpOutputTable ( 
                        EntityType ,    
                        EntityTypeId ,    
                        RowSeq ,   
                        RetailElementId ,
                        FieldValue ,    
                        FieldName ,    
                        ValueSeq ,    
                        CreateDatetime , 
                        ChangedDatetime ,
                        RowStatus, changedbyid)
Advertisements