Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter stored procedure if condition is met

I am looking to alter a stored procedure if a condition exists. I want to leave the stored procedure as is if the condition is not met, so drop/create is not really an option.

Trying to put the contents of ALTER PROC inside an IF block is throwing up errors for me. Any thoughts?

like image 353
Matt Avatar asked Apr 20 '10 18:04

Matt


1 Answers

IF (condition)
  EXEC ('ALTER PROC ...')

ALTER/CREATE PROC must be first in the batch so this is the only way. Unless you do this

IF NOT (condition)
   RAISERROR('abort connection with high severity', 20, 1)
GO
ALTER PROC ...

GO
like image 194
gbn Avatar answered Nov 11 '22 08:11

gbn