Here, I am giving a example of how to call a Sp
inside a SP. We can say this is a example of nested stored procedure.
Step 1: Create two simple stored procedure to
insert some data into two different tables.
usp_insert_into_Log1
to insert
data into tbl_log1
usp_insert_into_Log2 to
insert data into
tbl_log2
both accept four
parameters to insert the data.
Step 2: Here is a
requirement that if less then 50000 row filled in tbl_log1 then insert data
into tbl_log1 other wise another table tbl_log2.
Call then like given in query.
CREATE
PROCEDURE [dbo].[usp_insert]
(
@a
varchar(50),
@b
varchar(15),
@c
varchar(6),
@d
varchar(50)
)
AS
BEGIN
if
((select
count(*)
from tbl_Log1)
<50000)
exec
[dbo].[usp_insert_into_Log1]
@a,@b,@c,@d
else
exec
[dbo].[usp_insert_into_Log2]
@a,@b,@c,@d
END