How to execute stored procedure in another stored procedure in sql server -
i working on sql server 2008.
and have stored procedure in executing 1 more usp.
here want output of second usp , return main usp output parameter accordingly.
but main usp returning second usp value main usp value.
but want return main usp value.
below procedure :
alter proc [dbo].[usp_changestatus](@id int,@status int,@name varchar(300),@success int output ) set @success=0 begin try if exists(select * tbl_abc id= @id) begin if(@status =1) begin ----try-catch block---- begin try declare @addhoststatus int set @addhoststatus=0 exec @addhoststatus =usp_xyz @name,0,@address if(@addhoststatus=-3) begin set @success=1 end end try begin catch set @success=0 end catch ----end-try-catch block---- end if(@success=1) begin --do here end end end try begin catch set @success=0 end catch select @success
try this
suppose have 1 stored procedure this
first stored procedure:
create procedure loginid @username nvarchar(200), @password nvarchar(200) begin declare @loginid int select @loginid = loginid userlogin username = @username , password = @password return @loginid end
now want call procedure stored procedure below
second stored procedure
create procedure emprecord @username nvarchar(200), @password nvarchar(200), @email nvarchar(200), @isadmin bit, @empname nvarchar(200), @emplastname nvarchar(200), @empaddress nvarchar(200), @empcontactno nvarchar(150), @empcompanyname nvarchar(200) begin insert userlogin values(@username,@password,@email,@isadmin) declare @emploginid int exec @emploginid= loginid @username,@password insert tblemployee values(@empname,@emplastname,@empaddress,@empcontactno,@empcompanyname,@emploginid) end
as seen above, can call 1 stored procedure another