Either change the error code variable to a varchar or convert the variable when appending it to the string using cast or convert.
SET @SQL = @SQL + 'AND RS.ERROR_CODE = ' + CONVERT(VARCHAR,@p_Error)+ ''
As SQL is trying to convert the whole string to a number which is cannot do, so you need to make the number a string.