Question: I have the following query. 

```
with getstock as 
(
    select 
        a.bomparent, a.bomchild, a.bomqty, a.bompos, a.baltmethod, a.bomissue
    from 
        bom a
    where 
        bomparent = 'QZ10-0262601' and baltmethod = '1'

    union all

    select 
        parent.bomparent, parent.bomchild, parent.bomqty, parent.bompos, parent.baltmethod, parent.bomissue 
    from 
        getstock as a
    inner join 
        bom as parent, stock as s on parent.bomparent = a.bomchild
    where 
        parent.baltmethod = '1' and parent.bomparent = s.stocknum
)
select  *
from getstock

```

When I run it, I get the following error.

> 
> Msg 102, Level 15, State 1, Line 9  
> 
>  Incorrect syntax near ','.
> 
> 
> 

Where is the issue?

Answer: 
You can not use multiple tables in `JOIN`. It's possible in `FROM`, but I won't suggest that. That's the old-style `JOIN` syntax. You should rewrite your query using explicit `JOIN`:

```
with getstock as 
(
    select 
        a.bomparent, a.bomchild, a.bomqty, a.bompos, a.baltmethod, a.bomissue
    from 
        bom a
    where 
        bomparent = 'QZ10-0262601' and baltmethod = '1'

    union all

    select 
        parent.bomparent, parent.bomchild, parent.bomqty, parent.bompos, parent.baltmethod, parent.bomissue 
    from 
        getstock as a
    inner join 
        bom as parent on parent.bomparent = a.bomchild
    inner join 
        stock as s on parent.bomparent = s.stocknum
    where 
        parent.baltmethod = '1'
)
select  *
from getstock

```

For more reading: [Avoid using old-style `JOIN` syntax.](https://sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins)
```
with getstock as 
(
    select a.bomparent, a.bomchild, a.bomqty, a.bompos,
    a.baltmethod, a.bomissue
    from bom a
    where bomparent = 'QZ10-0262601' and baltmethod = '1'
    union all
    select parent.bomparent, parent.bomchild, parent.bomqty,
    parent.bompos,  parent.baltmethod, parent.bomissue 
    from getstock as a
    inner join bom as parent
     on parent.bomparent = a.bomchild
    inner join stock as s
     parent.bomparent = s.stocknum
   where parent.baltmethod = '1' 
)
select  *
from getstock

```