I have a Stored Procedure which contains an Insert
statement on it.
x
create procedure Sp1
(@oName varchar(50), @Address varchar(100))
as
begin
insert into Tb1(Name, Address)values(@oName, @Address)
end
From the above Stored Procedure, I want to have a condition from result of another Stored Procedure. With the following action:
select count(Branch) cBranch from Tb2 group by Branch
So, if cBranch
is zero
. Then execute Sp1
else do nothing.
Need advice please. Really appreciated.
Advertisement
Answer
Try This:
CREATE PROCEDURE SP_NAME
AS
DECLARE @Cndtn INT
SELECT @Cndtn=COUNT(Branch) FROM Tb2 GROUP BY Branch
IF(@Cndtn>0)
BEGIN
EXEC Sp1 @oName,@Address
END
ELSE
BEGIN
SELECT 'Else Clause' --Add an another SP name
END