我正在尝试生成一个新的 GUID 并将该值分配给NewReportID
. 但是,我不确定如果我替换@NewReportID
过程中的任何地方newid()
,它将为每一行生成一个新的 GUID。
我必须生成一个 GUID 并为 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