sql server - How to use newid() to assign a value to a stored procedure variable? -
i trying generate new guid , assign value newreportid
. but, unsure if replace @newreportid
everywhere in procedure newid()
generate new guid each line.
what have generate 1 guid , assign newreportid value of guid?
i have tried in variable declaration: @newreportid varchar(50)=newid()
gave me lots of errors.
alter procedure [dbo].[amendinsertduplicatefields] (@reportid varchar(50), @newreportid varchar(50)) begin insert [mvcomar].[dbo].[pridemvccollisionbegin] ([reportid], [localincidentnum], [version], [mtoreferenceno], [submitted]) select @newreportid, [localincidentnum], [version], [mtoreferenceno], [submitted] [mvcomar].[dbo].[pridemvccollisionbegin] [reportid]=@reportid; insert [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
use correct data type? uniqueidentifier
declare @newreportid uniqueidentifier set @newreportid = newid()
what flavour of sql-server using? tried said erroring:
i have tried in variable declaration: @newreportid varchar(50)=newid() gave me lots of errors.
but works me
Comments
Post a Comment