4
Answers

using the method output inserted.id

ToBe

ToBe

11y
1.3k
1
hi everyone 

i have 3 stored procedures one is the main sp  i'm using the method output inserted.id in the insertion Stored Procedure 

like this :

ALTER  PROCEDURE  [dbo].[sp_INSERT_REG_DETAILS]
 
 
  @SER_NO NVARCHAR (50),
  @REG_DATE DATE, 
  @NAME Varchar(50), 
  @RPF NVARCHAR (50),
  @ADDRESS VARCHAR(250),
  @COLG VARCHAR(50),
  @USR INT 
   
 
 
AS 
 
 Set NoCount On
 
 Begin
 
 
 Insert into REG_DETAILS
 
  (
    Ser_no,Reg_date,Name,Prf,Address,Golg,User
 
  )
 
  output inserted.ID
 
 
 
  Values
  (
 
    @SER_NO,@REG_DATE,@NAME,@RPF,@ADDRESS,@COLG,@USR
       
 
  )
 
 
 End


Second stored procedure:


ALTER PROCEDURE [dbo].[sp_INSERT_TYPE] 
  @ID int 
  @TYPE varchar (50)
AS
BEGIN
 
 
SET NOCOUNT ON;

  Insert into [dbo].[TYPE]
  (ID,TYPE)values(@ID,@TYPE)
 
END


Third stored procedure :

ALTER PROCEDURE [dbo].[sp_Insert_ST] 
  @ID  int 
  @ST varchar (50)= NULL
AS
BEGIN
 
  SET NOCOUNT ON;

  Insert into tblST
  (ID,stu)values(@ID,@STU)
 
END


when  I put it in my update stored procedure it will give syntax error where to put it in the update stored procedure ? after the values ? before the last statment GO or what should i do ?



Answers (4)