2012-05-30 71 views
7

可能重複:
The multi-part identifier could not be bound多部分組成的標識符無法綁定

這是我的查詢,不希望工作。

它說: 無法綁定多部分標識符「dbo.RunSequenceBatch.RunSequenceBatchName」。

您能否提供建議?

在此先感謝! :)

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 
+0

可能是一個錯字,但你有RunSeq.RunSequenceBatchName和進一步在您的查詢RunSequence.RunSequenceBatchName。似乎是不同的名稱相同? –

+0

考慮在查詢中使用簡短的別名。這可能會使您的查詢更具可讀性(即使對您自己),因此更容易發現此類錯誤。 –

回答

13

基本上,你的表名不匹配。

在你FROM您有:

FROM [dbo].[RunSequenceBatch] AS RunSeq 

你走樣[dbo].[RunSequenceBatch]換句話說,你指出,從現在起,將[dbo].[RunSequenceBatch]被稱爲RunSeq

但在你GROUP BY你不使用別名引用它。因爲查詢中唯一顯示的名稱中的別名dbo.RunSequenceBatch無法綁定。

變化

GROUP BY dbo.RunSequenceBatch.RunSequenceBatchName 

GROUP BY RunSeq.RunSequenceBatchName 

而且你會沒事的。

+0

很好的解釋。特別是「換句話說,你從這裏開始說[dbo]。[RunSequenceBatch]將被稱爲RunSeq」 –

相關問題