2011-02-15 54 views
1

CAn有人幫我修復這個SQL語句嗎?我嘗試從故事表和公司角色從成員表中檢索故事,創建日期,但出現錯誤:SQL錯誤多部分標識符

無法綁定多部分標識符「s.ProjectIterationMemberID」。 無法綁定多部分標識符「s.StoryID」。

SELECT s.Story, s.CreationDate, m.CompanyRole FROM Story s, Member m INNER JOIN  
ProjectIterationMember pim On m.MemberID = pim.MemberID AND 
pim.ProjectIterationMemberID = s.ProjectIterationMemberID INNER JOIN 
ProjectStoryFactors psf On s.StoryID = psf.StoryID JOIN AgileFactors af ON 
psf.AgileFactorID = af.AgileFactorID WHERE StoryCategoryID = 1 AND af.Name = '" + tag + "'" 

我的表結構如下:

Member {MemberID (PK), CompanyRole}

ProjectIterationMember {ProjectIterationMemberID (PK), MemberID (FK)}

Story {StoryID (PK), ProjectIterationMemberID, StoryCategoryID, Story, CreationDate}

ProjectStoryFactors {ProjectStoryFactorID (PK), StoryID, AgileFactorID}

AgileFactors {AgileFactorID (PK), Name}

+1

請在將來不要將SQL語句寫成好像他們是句子一樣。爲你的連接,where子句等使用新的行。它會使* *更多*比這裏更具可讀性。請參閱@ JonH的答案,瞭解格式良好的示例。儘管我更願意將ON和join條件保持在與join規範相同的行上,但他的可讀性要高得多。 – 2011-02-15 20:17:57

+0

WHERE子句末尾還有一個額外的雙引號 – theChrisKent 2011-02-15 20:20:32

+0

@theChrisKent - 它是某個IDE中字符串concat查詢的一個片段 – RichardTheKiwi 2011-02-15 20:23:18

回答

0
SELECT 
    s.Story, 
    s.CreationDate, 
    m.CompanyRole 
FROM 
    Story s 
INNER JOIN ProjectiterationMember pm 
ON 
    pm.ProjectIterationMemberID = s.ProjectIterationMemberID 
INNER JOIN Member m 
ON 
    m.MemberID = pm.MemberID 
INNER JOIN ProjectStoryFactors psf 
ON 
    psf.StoryID = s.StoryID 
INNER JOIN AgileFactors af 
ON 
    af.AgileFactorID=psf.AgileFactorID 
WHERE 
    s.StoreCategoryID = 1 AND af.Name = '" + tag + "'"  
2

你打破了ANSI加盟連鎖店與故事和成員之間的逗號

SELECT s.Story, s.CreationDate, m.CompanyRole 
FROM Story s 
INNER JOIN ProjectIterationMember pim 
On pim.ProjectIterationMemberID = s.ProjectIterationMemberID 
INNER JOIN Member m 
ON m.MemberID = pim.MemberID 
INNER JOIN ProjectStoryFactors psf 
On s.StoryID = psf.StoryID 
JOIN AgileFactors af 
ON psf.AgileFactorID = af.AgileFactorID 
WHERE StoryCategoryID = 1 AND af.Name = '" + tag + "'" 

這是您的查詢分解成塊。在FROM子句中混合ANSI和非ANSI使事情變得棘手。


SELECT s.Story,s.CreationDate,m.CompanyRole FROM

故事小號

, - 小逗號

m的INNER JOIN
ProjectIterationMember PIM在m.MemberID = pim.MemberID AND pim.ProjectIterationMemberID = s.ProjectIterationMemberID INNER JOIN ProjectStoryFactors PSF在s.StoryID = psf.StoryID JOIN AgileFactors AF ON psf.AgileFactorID = af.AgileFactorID

WHERE StoryCategoryID = 1 AND af.Name =「」 +標籤+ 「'」


別名「s」在第一個逗號部分定義,不能從第二部分「看到」。

相關問題