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 06, 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 06, 2014 7:29 PM This worked for the OP Answer marked as solution
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 6:32 PM
Points: 571, Visits: 3,743
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 06, 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 06, 2014 9:00 PM


SSC-Insane

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

Group: General Forum Members
Last Login: Today @ 10:42 AM
Points: 20,460, Visits: 14,086
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 07, 2014 5:08 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 6:32 PM
Points: 571, Visits: 3,743
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