sql - Stored Procedure statement terminated Error? -
i using below-stored procedure insert records view.
alter procedure [dbo].[spemployeeinsert] ( @date datetime ) begin declare @idinsert int select @idinsert= max (id)+1 dbo.emp insert [srv-rvs].dbo.emp (lastname,id) select [firstname],@idinsert + row_number() on (order [firstname]) - 1 drv-rds2014. [humanresources].[testemployeeview] modifieddate=@date insert [srv-rvs].dbo.empldf (civilid,jobtitle,issuedate,id) select [phonenumber],[jobtitle],[modifieddate],@idinsert + row_number() on (order [firstname]) - 1 drv-rds2014. [humanresources].[testemployeeview] modifieddate=@date end
while executing stored procedure returning below error
msg 515, level 16, state 2, procedure spemployeeinsert, line 42 cannot insert value null column 'id', table 'srv-rvs.dbo.emp'; column not allow nulls. insert fails. (1 row(s) affected) msg 515, level 16, state 2, procedure spemployeeinsert, line 48 cannot insert value null column 'id', table 'srv-rvs.dbo.empldf'; column not allow nulls. insert fails.
i trying pass date '01/04/2009;' copy source , insert destination using stored procedure.
regards
there problems procedure. first:
declare @idinsert int select @idinsert= max (id)+1 dbo.emp id= @idinsert
variable @idinsert
not initialized, value null
. need change to:
declare @idinsert int select @idinsert= max(id)+1 dbo.emp
second problem - @date
possible, view drv-rds2014. [humanresources].[testemployeeview]
return multiple values , insert queries fail cause of duplicate values in column id
. need change insert statements to:
insert [srv-rvs].dbo.emp (lastname,id) select [firstname],@idinsert + row_number() on (order [firstname]) - 1 drv-rds2014. [humanresources].[testemployeeview] modifieddate=@date insert [srv-rvs].dbo.empldf (civilid,jobtitle,issuedate,id) select [phonenumber],[jobtitle],[modifieddate],@idinsert + row_number() on (order [firstname]) - 1 drv-rds2014. [humanresources].[testemployeeview] modifieddate=@date
Comments
Post a Comment