so is @p_error an integer?
In which case you will need to change the
IF @p_Error IS NOT NULL
SET @SQL = @SQL + 'AND RS.ERROR_CODE = ' + @p_Error+ ''
INSERT INTO @RecipientDetails
EXEC (@SQL)
to
IF @p_Error IS NOT NULL
SET @SQL = @SQL + 'AND RS.ERROR_CODE = ' + Cast(varchar(20),@p_error)+ ''
INSERT INTO @RecipientDetails
EXEC (@SQL)
and that should work.
_________________________________________________________________________
SSC Guide to Posting and Best Practices