How can i use MERGE Sql Statement or UPDATE statement for my below code. I am having a columnName called MachineName, other column values change but MachineName doesnot change. If the Column MachineName changes i need to insert the new values in a secondrow. If not i need to Update the same row. How can i do this. Is it a right approach ? Please help
MERGE INTO [devLaserViso].[dbo].[Machine] WITH (HOLDLOCK) USING [devLaserViso].[dbo].[Machine] ON (MachineName = MachineName) WHEN MATCHED THEN UPDATE SET MachineName = L1,ProgramName= ancdh.pgm, TotalCount= 10, RightCount=4, LeftCount= 3,ErrorCode=0,FinishingTime=fsefsefef WHEN NOT MATCHED THEN INSERT (MachineName, ProgramName, TotalCount, RightCount, LeftCount, ErrorCode, FinishingTime) VALUES (L02, djiwdn.pgm, 11, 5, 4, 0, dnwdnwoin);