添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
 1 DECLARE @LatestSyncTime DATETIME
 2  SET @LatestSyncTime = (SELECT MAX(SyncTime) FROM dbo.SyncLog WHERE
 3   TargetTable = 'PlatformStatistics.dbo.VehicleHistoryRecordSummary' AND SyncStatus = 1);        
 5 MERGE INTO dbo.VehicleHistoryRecordSummary AS T
 6 USING (SELECT vh.ID, pr.ID AS ProductID, pr.Name AS ProductName, vh.OBDID, vh.CreateTime AS RecordTime  
 7 FROM (SELECT * FROM SVRDB2_Diagnosis.dbo.VehicleHistoryRecordIndex
 8 WHERE @LatestSyncTime IS NULL OR CreateTime > @LatestSyncTime) vh
10 INNER JOIN SVRDB1_Platform.dbo.us_UserOBD uo
11 On vh.OBDID=uo.OBDID
12 INNER JOIN SVRDB1_Platform.dbo.us_UserOrder us
13 ON uo.ZJID = us.ZJID
14 INNER JOIN SVRDB1_Platform.dbo.pr_Product pr
15 ON us.ProductID = pr.ID
16 ) AS S
17 ON T.ID = S.ID
18 WHEN MATCHED
19 THEN UPDATE
20 SET
21 T.ProductID = S.ProductID,
22 T.ProductName = S.ProductName,
23 T.OBDID = S.OBDID,
24 T.RecordTime = S.RecordTime,
25 T.UpdateTime = GETDATE()
26 WHEN NOT MATCHED
27 THEN INSERT (
28 ID,  ProductID, ProductName, OBDID, RecordTime, AddTime, UpdateTime)
29 VALUES (ID,ProductID, ProductName, OBDID, RecordTime,GETDATE(),GETDATE());

帮忙看下哪里出问题了

 dbo.VehicleHistoryRecordSummary AS T
 6 USING (SELECT vh.ID, pr.ID AS ProductID, pr.Name AS ProductName, vh.OBDID, vh.CreateTime AS RecordTime  
 7 FROM (SELECT * FROM SVRDB2_Diagnosis.dbo.VehicleHistoryRecordIndex
 8 WHERE @LatestSyncTime IS NULL OR CreateTime > @LatestSyncTime) vh
10 INNER JOIN SVRDB1_Platform.dbo.us_UserOBD uo
11 On vh.OBDID=uo.OBDID
12 INNER JOIN SVRDB1_Platform.dbo.us_UserOrder us
13 ON uo.ZJID = us.ZJID
14 INNER JOIN SVRDB1_Platform.dbo.pr_Product pr
15 ON us.ProductID = pr.ID
16 ) AS S
17 ON T.ID = S.ID

你查一下这个on出来的结果,应该是VehicleHistoryRecordSummary表数据同一条会出来多次