7

Possible Duplicate:
The multi-part identifier could not be bound

This is my query that doesn't want to work.

It says: The multi-part identifier "dbo.RunSequenceBatch.RunSequenceBatchName" could not be bound.

Could you please advise?

Thanks in advance!!! :)

SELECT '30 May' AS [Date],
[RunSeq].[RunSequenceBatchName] AS [Batch Job Name] ,
RunSeqCat.CategoryDescription AS [Development Name] ,
[Systems].SystemName AS [System Area] ,
CAST((SUM(DumpSM37_Env3.Duration) / 60) AS NUMERIC(10, 2)) AS [Duration (mins)] 
FROM [dbo].[RunSequenceBatch] AS RunSeq 
LEFT JOIN DumpSM37_Env3 ON ([RunSeq].[RunSequenceBatchName] =  DumpSM37_Env3.[Job] 
AND DumpSM37_Env3.[ImportDate] BETWEEN  '30 May 2012 00:00:00' AND '30 May 2012 23:59:59'), 
[dbo].[RunSequenceType] AS RunSeqType, 
[dbo].[RunSequenceFrequency] AS RunSeqFrequency, 
RunSequenceCategory AS RunSeqCat, Category, [Systems]  
WHERE RunSeq.Status = 'Active' 
AND RunSeqFrequency.RunSequenceBatchID  = RunSeq.RunSequenceBatchID 
AND RunSeq.RunSequenceTypeID = RunSeqType.RunSequenceTypeID 
AND RunSeqCat.CategoryDescription = Category.Description 
AND Category.SystemArea = [Systems].SystemID 
AND DumpSM37_Env3.[Duration] > 0 
AND RunSeq.RunSequenceTypeID = 1 
AND RunSeqCat.RunSequenceBatchID = RunSeq.RunSequenceBatchID  
GROUP BY dbo.RunSequenceBatch.RunSequenceBatchName, DumpSM37_Env3.WorkerProcessID, 
ORDER BY [RunSeqFrequency].[Frequency] ASC, 
[RunSeqFrequency].[StartTime] ASC
Community
  • 1
  • 1
user1425357
  • 73
  • 1
  • 1
  • 3
  • Might be a typo but you have RunSeq.RunSequenceBatchName and further in your query RunSequence.RunSequenceBatchName. Seems to be the same with different names? – David Brabant May 30 '12 at 07:16
  • Consider using short aliases for tables in your queries. This might make your queries more readable (even to yourself) and thus easier to spot such errors in. – Andriy M May 30 '12 at 11:27

1 Answers1

14

Basically, you've mismatched your table names.

In your FROM you have:

FROM [dbo].[RunSequenceBatch] AS RunSeq 

You're aliasing [dbo].[RunSequenceBatch] In other words, you're stating that from here on out, [dbo].[RunSequenceBatch] will be referred to as RunSeq

But in your GROUP BY you don't refer to it using the alias. Because the alias in the only exposed name in the query, dbo.RunSequenceBatch can't be bound.

Change

GROUP BY dbo.RunSequenceBatch.RunSequenceBatchName

to

GROUP BY RunSeq.RunSequenceBatchName

And you'll be fine.

Code Magician
  • 23,217
  • 7
  • 60
  • 77
  • Great explanation. Especially "In other words, you're stating that from here on out, [dbo].[RunSequenceBatch] will be referred to as RunSeq" – Luke Belbina Nov 30 '12 at 16:24