新しいGUIDを生成し、その値をに割り当てようとしていますNewReportID
。@NewReportID
ただし、手順のすべての場所をそれで置き換えるnewid()
と、各行に新しいGUIDが生成されるかどうかはわかりません。
GUIDを1つだけ生成し、NewReportIDにGUIDの値を割り当てるにはどうすればよいですか?
私は変数宣言を試しました@NewReportID varchar(50)=newid()
が、それは私に多くのエラーを与えました。
ALTER PROCEDURE [dbo].[AmendInsertDuplicateFields] (@ReportID varchar(50), @NewReportID varchar(50))
AS
Begin
INSERT INTO [MVCOmar].[dbo].[PrideMVCCollisionBegin]
([ReportID], [LocalIncidentNum], [version], [MTOReferenceNo], [Submitted])
SELECT @NewReportID, [LocalIncidentNum], [version], [MTOReferenceNo], [Submitted]
FROM [MVCOmar].[dbo].[PrideMVCCollisionBegin] WHERE [ReportID]=@ReportID;
INSERT INTO [MVCOmar].[dbo].[PrideMVCCollisionDetails] ([Classification] ,
[ReportType] ,[CollisionDate] ,[CollisionDay] ,
[CollisionTime] ,[CollisionLoc] ,[ImpactLoc] ,[ThruLaneNo] ,
[Weather1] ,[Weather2] ,[Light] ,[TrafficControl] ,
[TrafficControlCond] ,[RoadChar1] ,[RoadChar2] ,
[RoadSurface1] ,[RoadSurface2] ,[RoadCond1] ,[RoadCond2] ,
[RoadSurfaceCond1] ,[RoadSurfaceCond2] ,[RoadAlignment1] ,
[RoadAlignment2] ,[RoadPavementMarking1] ,[RoadPavementMarking2] ,
[OtherCollisionLoc] ,[OtherImpactLoc] ,[OtherWeather1] ,
[OtherWeather2] ,[OtherLight] ,[OtherTraffic] ,
[OtherRoadSurface1] ,[OtherRoadSurface2] ,[OtherRoadSurfaceCond1] ,
[OtherRoadSurfaceCond2] ,[OtherClassification] ,
[DiagramDescription] ,[R1NumLanes] ,[R1MaxSpeed] ,
[R1AdviseSpeed] ,[R2NumLanes] ,[R2MaxSpeed] ,[R2AdviseSpeed] ,
[NumInvolved] ,[OfficerID] ,[Checked] ,[LastModified] ,
[LastModifiedBy] ,[StartTime] ,[EndTime] ,[Display] ,
[ReportID] ,[InitialImpactType] ,[OtherInitialImpactType] ,
[SelfReported])
SELECT [Classification] ,[ReportType] ,[CollisionDate] ,
[CollisionDay] ,[CollisionTime] ,[CollisionLoc] ,[ImpactLoc] ,
[ThruLaneNo] ,[Weather1] ,[Weather2] ,[Light] ,
[TrafficControl] ,[TrafficControlCond] ,[RoadChar1] ,
[RoadChar2] ,[RoadSurface1] ,[RoadSurface2] ,[RoadCond1] ,
[RoadCond2] ,[RoadSurfaceCond1] ,[RoadSurfaceCond2] ,
[RoadAlignment1] ,[RoadAlignment2] ,[RoadPavementMarking1] ,
[RoadPavementMarking2] ,[OtherCollisionLoc] ,[OtherImpactLoc] ,
[OtherWeather1] ,[OtherWeather2] ,[OtherLight] ,
[OtherTraffic] ,[OtherRoadSurface1] ,[OtherRoadSurface2] ,
[OtherRoadSurfaceCond1] ,[OtherRoadSurfaceCond2] ,
[OtherClassification] ,[DiagramDescription] ,[R1NumLanes] ,
[R1MaxSpeed] ,[R1AdviseSpeed] ,[R2NumLanes] ,[R2MaxSpeed] ,
[R2AdviseSpeed] ,[NumInvolved] ,[OfficerID] ,[Checked] ,
[LastModified] ,[LastModifiedBy] ,[StartTime]
End