duchovnick
Programmer
Hi,
I'd like my stored procedure to stop processing when a certain condition is not fulfilled. For example, if a table doesn't exist, i want it to show some message and cease processing. Code should be something like:
Thanks a lot !
I'd like my stored procedure to stop processing when a certain condition is not fulfilled. For example, if a table doesn't exist, i want it to show some message and cease processing. Code should be something like:
Code:
/*EXEC mysp table1, table2, 9*/
/*DROP PROC mysp*/
CREATE PROCEDURE mysp @table1 VARCHAR(15),@table2 VARCHAR(15),@myNumber VARCHAR(5)
AS
BEGIN TRANSACTION
DECLARE @myDynamicSQL VARCHAR(900)
SET @myDynamicSQL=
'
IF EXISTS (SELECT * FROM sysobjects WHERE name='''+@table1+''')
SELECT * FROM '+@table1+'
[COLOR=#ff0000]ELSE
'Cannot proceed, table doesnt exist !'
stop running
[/color]
'
EXEC (@myDynamicSQL)
COMMIT
GO