Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntax Error with Multi-Table Joins Expand / Collapse
Author
Message
Posted Thursday, February 6, 2014 7:07 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, February 17, 2014 5:45 PM
Points: 10, Visits: 29
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
Post #1538971
Posted Thursday, February 6, 2014 7:29 PM This worked for the OP Answer marked as solution
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 8:21 PM
Points: 697, Visits: 4,476
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.
Post #1538972
Posted Thursday, February 6, 2014 7:58 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, February 17, 2014 5:45 PM
Points: 10, Visits: 29
Well, of course I knew that. (not!) Thanks for your very timely help!
Post #1538978
Posted Thursday, February 6, 2014 9:00 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 9:44 PM
Points: 21,187, Visits: 14,879
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1538986
Posted Friday, February 7, 2014 5:08 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 8:21 PM
Points: 697, Visits: 4,476
Yep, makes it MUCH easier to see what you were doing wrong. Way to go, young Jedi.
Post #1539447
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse