June 2, 2008 at 10:57 am
while running the below query.It is giving the error as
'Syntax error in JOIN operation.'
select first(SC_NAMES.SC_Name) as [Source],DQ1.[SrcCode] as [SourceCode],count(DQ1.[csts.ID]) as [Number of Donations],sum(DQ2.DonAmt) as [DonationAmount]
FROM @Datalink.Query(1).Name@ DQ1, @Datalink.Query(2).Name@ DQ2
LEFT JOIN DQ1 on SC_NAMES.SC_CODE = DQ1.SrcCode
where DQ1.id=DQ2.id Group By DQ1.SrcCode
June 2, 2008 at 11:20 am
SC_NAMES is not a table in the FROM list.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 2, 2008 at 11:25 am
And...
FROM @Datalink.Query(1).Name@ DQ1,
@Datalink.Query(2).Name@ DQ2
LEFT JOIN DQ1 on SC_NAMES.SC_CODE = DQ1.SrcCode
You've got a couple of other problems. You're mixing a variable in for the schema owner? You can't do that. You're mixing ANSI joins and NON-ANSI join syntax. Something along these lines would be more appropriate (I'm assuming Query is a udf):
FROM dbo.Query(1) DQ1
INNER JOIN dbo.Query(2) DQ2
ON DQ1.ID = DQ2.ID
LEFT JOIN dbo.SC_NAMES
ON DQ1.SrcCode = SC_NAMES.SC_CODE
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply