Error converting data type varchar to numeric I keep getting this error and I dont  understand why. I checked all CONVERT functions but not sure where is the issue.
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.

This is the query and you can see Line 1 does not have any type of conversion.
SELECT 
  'Entity Code|Department Code|Job Code|Pay Code|Pay Period Code|Employee Code|Fiscal Year|Time 
  Class|Unit Type|Amount|Home Entity Code|Home Department|Pay Period End Date' AS PRL_HEADERR
UNION ALL SELECT       
  (ISNULL(RTRIM(LTRIM(RIGHT(REPLICATE(0, 4) + SUB.DIST_COMPANY, 4))), '')    
  + '|' + ISNULL(RTRIM(LTRIM(RIGHT(REPLICATE(0, 4) + SUB.DST_ACCT_UNIT2, 4))), '')   
  + '|' + ISNULL((SUB.JOB_CODE2), '')                      
  + '|' + ISNULL((SUB.PAY_CODE2), '')                      
  + '|' + ISNULL((SUB2.PAYPERIOD), '')                     
  + '|' + ISNULL(
      (CASE WHEN SUBSTRING(RIGHT(REPLICATE(0, 7) + SUB.EMPLOYEE, 7),1,1)='0' 
      THEN SUBSTRING(RIGHT(REPLICATE(0, 7) + SUB.EMPLOYEE, 7),2,LEN(RIGHT(REPLICATE(0, 7) + 
      SUB.EMPLOYEE, 7))) 
      ELSE RIGHT(REPLICATE(0, 7) + SUB.EMPLOYEE, 7) END), '')    
  + '|' +       ISNULL((SUB.FISCAL_YEAR), '')                    
  + '|' +       ISNULL((SUB.TIME_CLASS), '')                     
  + '|' +       ISNULL((SUB.UNIT_TYPE), '')                      
  + '|' +       ISNULL((SUB.UNIT_VALUE), '')                     
  + '|' +       ISNULL(HOME_ENTITY_CODE, '')                     
  + '|' +       ISNULL(HOME_DEPARTMENT, '')                     
  + '|' +     ISNULL(PAY_PER_END_DATE, ''))  AS PRL_HEADER
FROM
 (
  SELECT
     TOP 100 PERCENT DIST_COMPANY,
     LTRIM(RTRIM(DST_ACCT_UNIT)) AS DST_ACCT_UNIT2,
     LTRIM(RTRIM(JOB_CODE)) AS JOB_CODE2,
     LTRIM(RTRIM(PAY_CODE)) AS PAY_CODE2,
     PER_END_DATE,
     EMPLOYEE,
     (CONVERT(VARCHAR(4), GL_DATE, 112)) AS FISCAL_YEAR,
     'A' AS TIME_CLASS,
     'Hours' AS UNIT_TYPE,
     HOURS AS UNIT_VALUE,
     COMPANY AS HOME_ENTITY_CODE,
     LTRIM(RTRIM(HM_ACCT_UNIT)) AS HOME_DEPARTMENT,
     CONVERT(VARCHAR(8), PER_END_DATE,112) AS PAY_PER_END_DATE 
  FROM
     TEST_TABLE
  WHERE
     (
        GL_DATE &gt;= CAST('20200101' AS DATETIME)
        AND GL_DATE &lt;= CAST('20201231' AS DATETIME)
     )
  UNION ALL
  SELECT TOP 1000
     DIST_COMPANY,
     LTRIM(RTRIM(DST_ACCT_UNIT)) AS DST_ACCT_UNIT2,
     LTRIM(RTRIM(JOB_CODE)) AS JOB_CODE2,
     LTRIM(RTRIM(PAY_CODE)) AS PAY_CODE2,
     PER_END_DATE,
     EMPLOYEE,
     (CONVERT(VARCHAR(4), GL_DATE, 112)) AS FISCAL_YEAR,
     'A' AS TIME_CLASS,
     'Amount' AS UNIT_TYPE,
     WAGE_AMOUNT AS UNIT_VALUE,
     COMPANY AS HOME_ENTITY_CODE,
     LTRIM(RTRIM(HM_ACCT_UNIT)) AS HOME_DEPARTMENT,
     CONVERT(VARCHAR(8), PER_END_DATE,112) AS PAY_PER_END_DATE 
  FROM
     TEST_TABLE
  WHERE
     (
        GL_DATE &gt;= CAST('20200101' AS DATETIME)
        AND GL_DATE &lt;= CAST('20201231' AS DATETIME)
     )
  ORDER BY
     EMPLOYEE,
     PER_END_DATE 
 )
 AS SUB 
 INNER JOIN
  (
     SELECT
        ROW_NUMBER() OVER (ORDER BY PP_END_DATE) AS ROWNUM,
        SUB3.PP_END_DATE,
        (
           (CONVERT(VARCHAR(4), SUB3.PP_END_DATE, 112) + '-') + ROWNUM
        )
        AS PAYPERIOD
     FROM
        (
           SELECT DISTINCT
              TOP 100 PERCENT PER_END_DATE AS PP_END_DATE 
           FROM
              TEST_TABLE
           WHERE
              (
                 PER_END_DATE &gt;= CAST('20200101' AS DATETIME)
                 AND PER_END_DATE &lt;= CAST('20201231' AS DATETIME) 
              )
           ORDER BY
              PER_END_DATE 
        )
        AS SUB3 
  )
  AS SUB2 
  ON SUB2.PP_END_DATE = SUB.PER_END_DATE

This query was written in Oracle by someone else and I'm converting it to MS SQL.  Also the app is large and legacy, written in Cobol.  Good thing is there is not a lot of data here therefore performance is not a big concern.
It's because the first parameter of the REPLICATE function is a VARCHAR, not int. Please see the documentation here.
Instead of doing REPLICATE(0, 4) you'll want to do REPLICATE('0', 4) etc.
The error itself can be a little confusing when it says the word convert, because it doesn't necessarily mean the CONVERT function, rather it's trying to do implicit conversion of the INT value 0 to a VARCHAR value since that is the data type of the parameter for the REPLICATE function. This error can occur for any function that expects a certain data type for its parameter but is passed in a value that's a different data type that is unable to be implicitly converted.
An example of implicit conversion that would work, is if a function had a parameter that was of type BIGINT and you passed in an INT value like 13 instead.