我怀疑这个问题与MIN语句有关,但不确定如何修复它:
UPDATE t1
SET t1.PrintDate = MIN(t2.[Print Date])
FROM [Data Checking].[dbo].[MonthlyReads] t1
INNER JOIN [Data Checking].[dbo].[BILLWINDOWS] t2
ON t1.MRU = t2.[MR Unit]
WHERE t2.[Print Date] > t1.[ReadingDate]
感谢您的帮助。
答案 0 :(得分:1)
你可以这样做:
;WITH t2 ([MR Unit] , [Print Date]) as
(
SELECT [MR Unit] , MIN([Print Date])
FROM [Data Checking].[dbo].[BILLWINDOWS]
GROUP BY [MR Unit]
)
UPDATE t1
SET t1.PrintDate = t2.[Print Date]
FROM [Data Checking].[dbo].[MonthlyReads] t1
INNER JOIN t2
ON t1.MRU = t2.[MR Unit]
WHERE t2.[Print Date] > t1.[ReadingDate]