我需要一些有关 SQL Server 游标的帮助:
Declare @DCursor cursor, @OldIndividualID uniqueIdentifier,
@NewIndividualID UniqueIdentifier, @NewUniqueColID uniqueIdentifier
Set @DCursor = Cursor For
Select IndividualID From [MVCOmar2].[dbo].PrideMVCDriver
Where UniqueColID='895AE0DE-D2CF-461E-ADA9-14FB8BB59640'
Set @NewUniqueColID=NEWID()
Open @DCursor
Fetch Next From @DCursor Into @OldIndividualID
While (@@FETCH_STATUS = 0)
Begin
Set @NewIndividualID=NEWID()
INSERT INTO [MVCOmar2].[dbo].[PrideMVCCollisionDiagram] ([IndividualID], [ColDiagram],
[dateEntered] ,[OfficerID] ,[UniqueColID] ,[ESDEditDiagram])
SELECT @NewIndividualID,[ColDiagram] ,[dateEntered] ,[OfficerID] ,
@NewUniqueColID ,[ESDEditDiagram]
FROM [MVCOmar2].[dbo].[PrideMVCCollisionDiagram]
WHERE [IndividualID]=@OldIndividualID;
Fetch Next From @DCursor Into @OldIndividualID
End
Close @DCursor
Deallocate @DCursor
我有上面的代码并且该Select
语句工作正常,它返回 2 行,但由于某些奇怪的原因,游标无法正常工作,这意味着插入语句没有插入任何没有意义的东西,因为各个 id 应该存在。该 select 语句返回 2 个单独的 ID,因此 insert 语句应该可以工作,但它不是,所以我不知道该怎么做......