Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to EXEC a stored procedure from a CASE statement

Status
Not open for further replies.

MrJRW

IS-IT--Management
Feb 6, 2002
47
US
Good Morning

I would like to EXEC stored procedures as a result of flow control.

My code:

SELECT
CASE
WHEN Count(*) = 0 THEN EXEC Proc1
WHEN Count(*) > 0 THEN EXEC Proc2
END
FROM Table1
WHERE Table1.flag = 'Y'

Any Ideas ?

 
SELECT
CASE
WHEN Count(*) = 0 THEN EXEC Proc1
WHEN Count(*) > 0 THEN EXEC Proc2
END
FROM Table1
WHERE Table1.flag = 'Y'

As the count is dictating the flow, then use a variable
i.e.
DECLARE @v_Count bigint
SELECT Count = Count(*)
FROM Table1
WHERE Table1.flag = 'Y'
If @v_Count = 0
THEN EXEC Proc1
ELSE Exec Proc2

I think it should do the same thing as you are asking.

 
Code:
if exists (select * from table1 where flag = 'Y')
   exec proc2
else
   exec proc1
 
Thanks !!

I got it working

JRW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top