我想在下面的格式檢索數據:的爲什麼我在我的查詢中獲取SQL語法錯誤?
Story | Story Type | Creation Date | Company Role | Tag 1 | Tag 2 | Tag 3
negative iii | Negative | 21/02/2011 | Business Analyst | Project Duration | Team Size | Process
negative ccc | Negative | 22/02/2011 | Admin | Workspace Layout | Organisational | Process
代替:
Story | StoryCategoryID | CreationDate | CompanyRole | Name
negative iii | 1 | 21/02/2011 | Business Analyst | Project Duration
negative iii | 1 | 21/02/2011 | Business Analyst | Team Size
negative iii | 1 | 21/02/2011 | Business Analyst | Process
negative ccc | 1 | 22/02/2011 | Admin | Workspace Layout
negative ccc | 1 | 22/02/2011 | Admin | Organisational and Reporting Structure
negative ccc | 1 | 22/02/2011 | Admin | Process
,但我收到以下錯誤:
1)附近有語法錯誤關鍵字AS,
2)Z附近語法不正確
這是我的SQL,請幫忙!
SELECT
Story,
CASE StoryCategoryID
WHEN 1 THEN 'Negative'
WHEN 0 THEN 'Positive'
ELSE CAST(StoryCategoryID as varchar(10)) as StoryCategoryID,
CreationDate,
CompanyRole,
MAX(CASE WHEN Z.MinName = af2.Name THEN af2.Name ELSE '' END) as Tag1 ,
MAX(CASE WHEN Z.MinName <> af2.Name AND Z.MaxName <> af2.Name THEN af2.Name ELSE '' END) as Tag2,
MAX(CASE WHEN Z.MaxName = af2.Name THEN af2.Name ELSE '' END) as Tag3
FROM (SELECT s.Story , s.StoryCategoryID ,
CONVERT(VARCHAR(10), s.CreationDate, 103) AS CreationDate ,
m.CompanyRole , af.AgileFactorID , MIN(af.Name) MinName ,
MAX(af.Name) MaxName
FROM Story s
INNER JOIN ProjectIterationMember pm
ON pm.ProjectIterationMemberID = s.ProjectIterationMemberID
INNER JOIN Iterations i
ON i.ProjectIterationID = pm.ProjectIterationID
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 i.ProjectID = '" + proj_id + "'"
GROUP BY s.Story,
s.StoryCategoryID,
CONVERT(VARCHAR(10), s.CreationDate, 103),
m.CompanyRole, af.AgileFactorID) Z
INNER JOIN AgileFactors af2 ON af2.AgileFactorID = Z.AgileFactorID
GROUP BY Story, StoryCategoryID, CreationDate, CompanyRole
您是否嘗試過縮進代碼並註釋掉區塊以縮小錯誤的位置? – 5arx 2011-02-23 23:15:58
你可以用空白格式表示SQL並重新發布嗎? – Oliver 2011-02-23 23:15:58