Syntax Error with Multi-Table Joins

  • Newbie here. Having trouble with a multi-table join exercise, code below. A two-table join works fine but more than that produces this error:

    Msg 102, Level 15, State 1, Line 11

    Incorrect syntax near 'vt_exam_details'.

    Every query with 3 or more tables produces this error on the second joined table. I'm running 2008R2 on Windows 7.

    use a_vets;

    go

    SELECT

    ED.ex_id,

    EH.ex_date,

    S.srv_id,

    ED.ex_fee

    FROM

    vt_animals as A

    INNER JOIN

    vt_exam_headers as EH on (A.an_id = EH.an_id)

    vt_exam_details as ED on (EH.ex_id = ED.ex_id)

    vt_services as S on (ED.srv_id = S.srv_id)

    WHERE

    A.an_type in ('rodent')

    ORDER BY

    S.srv_id;

    GO

  • The problem is that you left out the other INNER JOIN statements:

    ...

    FROM

    vt_animals as A

    INNER JOIN

    vt_exam_headers as EH on A.an_id = EH.an_id

    INNER JOIN

    vt_exam_details as ED on EH.ex_id = ED.ex_id

    INNER JOIN

    vt_services as S on ED.srv_id = S.srv_id

    Hope that helps.

  • Well, of course I knew that. (not!) Thanks for your very timely help!

  • timSF (2/6/2014)


    Well, of course I knew that. (not!) Thanks for your very timely help!

    Well you were close and did a fine job of posting your exact problem.

    Those who answer questions on these forums appreciate that.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Yep, makes it MUCH easier to see what you were doing wrong. Way to go, young Jedi.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply