Assuming this is a stored procedure you probably want something along the lines of this
IF OBJECT_ID('sp_demo') > 0 DROP PROC sp_demo
go
CREATE PROC sp_demo (@OptParam1 varchar(50),@OptParam2 varchar(50),@OptParam3 varchar(50))
AS
IF @OptParam3 not like '_-____-___-___-__'
Begin
Print 'Error: Invalid Code'
Return 1
End
/*
If we got here then the parameter is validated
*/
PRINT '@OptParam3 is valid:'
PRINT @OptParam3
Return 0
You can check this by doing the following
/* Driver to test the stored procedure */
DECLARE @return_Code int
EXEC @return_Code = sp_demo 'parameterA','parameterB','A-1213-465-798-01';
PRINT @return_Code
But really you should probably be raising an error in your code if your input parameters are invalid. This will come through as a trapable error in your front end
IF OBJECT_ID('sp_demo') > 0 DROP PROC sp_demo
go
CREATE PROC sp_demo (@OptParam1 varchar(50),@OptParam2 varchar(50),@OptParam3 varchar(50))
AS
IF @OptParam3 not like '_-____-___-___-__'
Begin
RAISERROR (N'Error: Invalid Code "%s"',16,1 ,@OptParam3)
return @@ERROR
End
/*
If we got here then the parameter is validated
*/
PRINT '@OptParam3 is valid:'
PRINT @OptParam3
Return 0