I am executing the following query : 

```
WITH rg(id, childid, NAME) 
     AS (SELECT id, 
                0 ChildID, 
                NAME 
         FROM   kuaf 
         WHERE  id = 1000 
         UNION ALL 
         SELECT c.id, 
                c.childid, 
                k.NAME 
         FROM   kuafchildren c 
                JOIN rg p 
                  ON ( c.childid = p.id ) 
                JOIN kuaf k 
                  ON ( c.id = k.id )) 
SELECT DISTINCT ka.id 
FROM   rg, 
       lm_approvals app 
       JOIN kuaf ka 
         ON ( ka.id = app.useridentifier ) 
       JOIN dtree dt 
         ON ( dt.dataid = app.dataid ) 
WHERE  app.dataid = 25773 
       AND app.isapproved = 0 
       AND Replace(ka.NAME, ka.type + '_', dt.ownerid + '_') = rg.NAME 

```

But I am ending with the following error:

> 
> Types don't match between the anchor and the recursive part in column
>  "ChildID" of recursive query "rg".
> 
> 
>