In the query do not observe the DECLARE @ COUNT_PCH of.
You can test the results of the consultation to see the problem,
comment "if @ COUNT_PCH> 0" to always define an error.
And the error message says @ error_message = 'FAILED' + convert (varchar, @ Serial) + ',' + Convert (varchar, @ COUNT_PCH).
Thus the message you know the value of variables to make decisions.
I could not do the test because they do not define it as a value to the serial