|
我如何在下面的代码中使用MERGESql语句或UPDATE语句。我有一个称为columnName的MachineName列,其他列值更改了,但是MachineName却没有更改。如果列MachineName更改,则需要在第二行中插入新值。如果不是,我需要更新同一行。我怎样才能做到这一点。这是正确的方法吗?请帮忙
! H0 D% s5 @6 k3 b1 u, y. y& }MERGE INTO [devLaserViso].[dbo].[Machine] WITH (HOLDLOCK) ) n, ? [' }' g
USING [devLaserViso].[dbo].[Machine]
6 [3 \. [1 k1 B' BON (MachineName = MachineName)7 o; v) J+ |% L5 N" }
WHEN MATCHED . G* z! y* K, X2 ^# {3 O- Q2 @
THEN UPDATE SET MachineName = L1,ProgramName= ancdh.pgm, TotalCount= 10, RightCount=4, ' I, f' o1 X6 I: A
LeftCount= 3,ErrorCode=0,FinishingTime=fsefsefef I" z7 n, P' I, H' @
WHEN NOT MATCHED
p( ]- Z% B$ N1 _ M THEN INSERT (MachineName, ProgramName, TotalCount, RightCount, LeftCount, ErrorCode, FinishingTime) 7 j, R9 t+ H& x& i9 P
VALUES (L02, djiwdn.pgm, 11, 5, 4, 0, dnwdnwoin);
( M& V4 x C+ H! G5 _! p. F! \ % I) p. k( ^7 L, ^3 Z$ Y/ h
解决方案: |
|