Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question on nested joins

Author  Topic 

Niki
Yak Posting Veteran

51 Posts

Posted - 2012-12-05 : 18:32:20
Is it possible to have nested joins like below. It is giving me error though.

Select S.ID
FROM dbo.tblssms S LEFT JOIN
([DBname].[dbo].[tblAdditionalPrograms]
INNER JOIN [DBname].[dbo].[tblAdditionalProgramsDefs]
ON [DBname].[dbo].[tblAdditionalPrograms].[RecCodeID] = [DBname].[dbo].[tblAdditionalProgramsDefs].[ID])
P ON S.ID = P.ID

The error I am getting is 'Incorrect syntax near 'P'.


Niki

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2012-12-05 : 18:40:04
Would this work? I'm not sure which table you are trying to alias as "P".[CODE]Select S.ID
FROM dbo.tblssms S LEFT JOIN
([DBname].[dbo].[tblAdditionalPrograms] P
INNER JOIN [DBname].[dbo].[tblAdditionalProgramsDefs]
ON P.[RecCodeID] = [DBname].[dbo].[tblAdditionalProgramsDefs].[ID])
ON S.ID = P.ID[/CODE]


=================================================
Hear the sledges with the bells - silver bells!
What a world of merriment their melody foretells!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-05 : 20:02:51
You mean this one

Select S.ID
FROM dbo.tblssms S
LEFT JOIN
(
Select ID,* from [DBname].[dbo].[tblAdditionalPrograms]
INNER JOIN [DBname].[dbo].[tblAdditionalProgramsDefs] ON [DBname].[dbo].[tblAdditionalPrograms].[RecCodeID] = [DBname].[dbo].[tblAdditionalProgramsDefs].[ID]
)P ON S.ID = P.ID
Go to Top of Page

Niki
Yak Posting Veteran

51 Posts

Posted - 2012-12-06 : 11:11:48
Yes, Sodeep.
Thank you! it worked.

Niki
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-06 : 12:13:37
quote:
Originally posted by Niki

Yes, Sodeep.
Thank you! it worked.

Niki



NP
Go to Top of Page
   

- Advertisement -