我有一个程序可以更新表中的 x 行。我创建了一个日志表,其中包含所有更新行的记录。所以每次我运行我的程序时,它都会产生影响。5 行,然后将这 5 行插入到我的日志表中。
这是我的程序:
UPDATE dbo.ImportAdvTemp
SET dbo.ImportAdvTemp.DeliveryAdrID = dbo.ImportAdvTemp_IMPORTED.DeliveryAdrID
FROM dbo.ImportAdvTemp, dbo.ImportAdvTemp_IMPORTED
WHERE
ISNULL(dbo.ImportAdvTemp.DeliveryName, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryName, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryStreet,'') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryStreet, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryHouseNumber, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryHouseNumber, '') AND
ISNULL(dbo.ImportAdvTemp.DeliverySubCity, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliverySubCity, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryPostCode, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryPostCode, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryCity, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryCity, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryCountry, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryCountry, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryCustomer, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryCustomer, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryAlias, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryAlias, '') AND
ISNULL(dbo.ImportAdvTemp.DeliveryNote, '') = ISNULL(dbo.ImportAdvTemp_IMPORTED.DeliveryNote, '') AND
dbo.ImportAdvTemp.toManualProc = 1 and dbo.ImportAdvTemp.Closed = 0 and(dbo.ImportAdvTemp.DeliveryAdrID IS NULL or dbo.ImportAdvTemp.PickupAdrID IS NULL or dbo.ImportAdvTemp.DeliveryAdrID = 0 or dbo.ImportAdvTemp.PickupAdrID = 0)
我需要弄清楚哪些行受到影响,然后使用该行中的数据插入到我的日志表中。我已阅读有关使用游标的信息,这是唯一的方法吗?