1

我有以下代码,我收到错误无法解析,我仍在学习 TRIM 代码,所以它可能在那个

SELECT    
   LEFT(dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 2) AS STATE, 
   (dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR) AS EHP_Code, RTRIM(LTRIM([FCT_TYP_CD])) + ' (' + RTRIM(LTRIM([Dep_Typ_CD]) + ')' AS [Course Owner]
   dbo.COL_TBL_VCOURSE.TNG_NA AS [Course Title]
FROM         
   dbo.COL_V_Cost_GEMS_Detail 
INNER JOIN
   dbo.COL_TBL_VCOURSE ON dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR = dbo.COL_TBL_VCOURSE.TNG_SYS_NR 
INNER JOIN
   dbo.COL_TBL_VCOURSE_TYP ON dbo.COL_TBL_VCOURSE.TNG_MDA_TYP_CD = dbo.COL_TBL_VCOURSE_TYP.TNG_TYP
GROUP BY 
   dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 
   LEFT(dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 2), 
   dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR, 
   dbo.COL_TBL_VCOURSE.TNG_NA
4

1 回答 1

1

您缺少右括号:

RTRIM(LTRIM([FCT_TYP_CD])) 
    + ' (' 
    RTRIM(LTRIM([Dep_Typ_CD])) <-- this is missing
    + ')' AS [Course Owner]

你在后面缺少一个逗号[Course Owner]

您的查询应该是:

SELECT LEFT(dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 2) AS STATE, 
  (dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR) AS EHP_Code, 
  RTRIM(LTRIM([FCT_TYP_CD])) 
    + ' (' 
    RTRIM(LTRIM([Dep_Typ_CD])) --< parentheses missing
    + ')' AS [Course Owner],  -- < comma missing
  dbo.COL_TBL_VCOURSE.TNG_NA AS [Course Title]
FROM dbo.COL_V_Cost_GEMS_Detail 
INNER JOIN dbo.COL_TBL_VCOURSE 
  ON dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR = dbo.COL_TBL_VCOURSE.TNG_SYS_NR 
INNER JOIN dbo.COL_TBL_VCOURSE_TYP 
  ON dbo.COL_TBL_VCOURSE.TNG_MDA_TYP_CD = dbo.COL_TBL_VCOURSE_TYP.TNG_TYP
GROUP BY dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 
  LEFT(dbo.COL_V_Cost_GEMS_Detail.FAC_LOC_NR, 2), 
  dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR, 
  dbo.COL_TBL_VCOURSE.TNG_NA
于 2013-01-24T16:02:23.227 回答