title: Error while converting varchar to bigint
body: <p>I am executing the below query. In the query ChID is not the column of Cat table. For that I am placing 0 as ChID and converting it to bigint datatype to match with the column's datatype of CatAtt. But I am getting the following error:</p>
  
  <blockquote>
    <p>Msg 8114, Level 16, State 5, Line 1<br>
    Error converting data type varchar to bigint.</p>
  </blockquote>
  
  <p>I have executed similar query in Oracle with Oracle related changes and I got the results.</p>
  
  <pre><code>WITH rg (ID, ChID, Name) AS 
  (
      SELECT
          ID,
          CAST(0 AS bigint) ChID,
          Name
      FROM Cat
      WHERE ID = 1000
  
      UNION ALL
  
      SELECT
          c.ID,
          c.ChID,
          k.Name
      FROM CatAtt c
      JOIN rg p ON (c.ChID = p.ID)
      JOIN Cat k ON (c.ID = k.ID)
  )
  SELECT DISTINCT
      ka.ID
  FROM 
      rg, Parent app
  JOIN 
      Cat ka ON (ka.ID = app.UserIdentifier)
  JOIN 
      Owner dt ON (dt.ID = app.ID)
  WHERE 
      app.ID = 25773
      AND app.aprroved = 0
      AND REPLACE(ka.Name, ka.Type + '_', dt.OwnerID + '_') = rg.Name
  </code></pre>