SQL错误多部分标识符

时间:2011-02-15 20:11:10

标签: 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 + "'"

我的表格结构如下:

  

会员{MemberID(PK),CompanyRole}

     

ProjectIterationMember   {ProjectIterationMemberID(PK),   会员ID(FK)}

     

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

     

ProjectStoryFactors   {ProjectStoryFactorID(PK),StoryID,   AgileFactorID}

     

AgileFactors {AgileFactorID(PK),   名称}

2 个答案:

答案 0 :(得分: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 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 +”'“


别名“s”在第一个逗号部分定义,不能从第二部分“看到”。

答案 1 :(得分: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 + "'"