Reporting to SQL - Issue Converting Data

I have a script that runs a select and if the records don’t match, it
runs an insert to a sql table. I have done this in other scripts with
no problem. For some reason, the data is coming out as nvarchar and
can’t be converted to numeric. I tried to_i, but the script blows up.

Attached is the part of the script that is having an issue. I have a
definition for the insert of the data and then select statements to get
the counts that I need to insert.

Line 39 is the insert, and the 2 counts that are being inserted seem to
be the issue. Any ideas would be appreciated.

Thank you