DECLARE @a uniqueidentifier, @b uniqueidentifier, @c datetime, @d numeric(15, 2)
DECLARE MyCursor CURSOR FOR
SELECT Z.ID, Z.Name, Z.Date, (V1.Credit - V2.Debet) AS Money
FROM dbo.Table1 V1
INNER JOIN dbo.Table1 V2
ON V2.Name = V1.Name AND V2.ID = V1.ID AND V2.Date = V1.Date
INNER JOIN dbo.Table2 Z
ON Z.Name = V1.Name AND Z.ID = V1.ID AND Z.Date = V1.Date
WHERE V1.Date = DATEADD(Day, Z.AllowedDays, V2.Date)
OPEN MyCursor
FETCH NEXT FROM MyCursor INTO @a, @b, @c, @d
-- Get stuck here!!!
print 'My Cursor goes ahead'
WHILE @@FETCH_STATUS = 0
BEGIN
...
有人可以解释为什么它会卡在我的案例中吗?我无法理解原因,因为独立 Select 正在自行完成。