SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Syntax Error with Multi-Table Joins


Syntax Error with Multi-Table Joins

Author
Message
timSF
timSF
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
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

pietlinden
pietlinden
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13920 Visits: 14120
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.
timSF
timSF
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Well, of course I knew that. (not!) Thanks for your very timely help!
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)

Group: General Forum Members
Points: 66033 Visits: 18570
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

pietlinden
pietlinden
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13920 Visits: 14120
Yep, makes it MUCH easier to see what you were doing wrong. Way to go, young Jedi.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search