FROM子句出错:靠近'{'。无法解析查询文本

时间:2012-05-30 22:06:27

标签: sql tsql reporting-services ssrs-2008 bids

我正在尝试对数据集执行以下查询:

SELECT 
  S.CUSIP, S.SecName, 
  ISNULL(RA.FinInstCode, '') AS RemarketingAgent, 
  S.IssueDate, S.MaturityDate, F2.FinInstName AS Trustee, 
  CASE WHEN SC1.ExpirationDate IS NULL 
    THEN '' ELSE ISNULL(F1.FinInstCode, '') END 
  AS CreditProvider, 
  CASE WHEN SC1.ExpirationDate IS NULL 
    THEN '' ELSE ISNULL(C1.CreditEnhancementCode, '') END 
  AS CreditType, 
  SC1.ExpirationDate AS CreditExpirationDate, 
  SC1.RefNum AS RefNumber
FROM
  dbo.SecurityCreditEnhancementProvider SC1, 
  dbo.FinInst F1, 
  dbo.LUCreditEnhancement C1, 
  { oj { oj dbo.Security S 
LEFT OUTER JOIN
  dbo.FinInst F2 ON S.TrusteeID = F2.FinInstID } 
LEFT OUTER JOIN
  dbo.FinInst RA ON S.RemarketingAgentID = RA.FinInstID }
WHERE
  S.SecID = SC1.SecID 
AND 
  SC1.CreditProviderID = F1.FinInstID 
AND 
  SC1.CreditEnhancementID = C1.CreditEnhancementID 
AND 
  C1.CreditEnhancementCode = 'LOC' OR
  C1.CreditEnhancementCode = 'LIQUIDITY' 
AND 
  (S.ActiveFlag = 'A') 
AND 
  (S.SecTypeID NOT IN (4, 7))
ORDER BY CreditExpirationDate

尝试运行查询时,我得到的错误是“FROM子句中的错误: '{'。无法解析查询。 “

非常感谢任何帮助解决此问题的方法。

谢谢,

编辑1:这是查询设计者更改代码后的样子:

FROM         { oj { oj { oj { oj { oj dbo.SecurityCreditEnhancementProvider SC1 LEFT OUTER JOIN
                  dbo.FinInst F1 ON SC1.CreditProviderID = F1.FinInstID } LEFT OUTER JOIN
                  dbo.LUCreditEnhancement C1 ON SC1.CreditEnhancementID = C1.CreditEnhancementID } LEFT OUTER JOIN
                  dbo.Security S ON S.SecID = SC1.SecID } LEFT OUTER JOIN
                  dbo.FinInst F2 ON S.TrusteeID = F2.FinInstID } LEFT OUTER JOIN
                  dbo.FinInst RA ON S.RemarketingAgentID = RA.FinInstID }

感谢大家的帮助。

1 个答案:

答案 0 :(得分:0)

在这种情况下格式化代码可能会有所帮助。您的FROM子句中的语法不正确。我还更新了查询以在所有表​​上使用JOIN语法,而不是在表之间使用逗号。

SELECT S.CUSIP
    , S.SecName
    , ISNULL(RA.FinInstCode, '') AS RemarketingAgent
    , S.IssueDate
    , S.MaturityDate
    , F2.FinInstName AS Trustee
    , CASE WHEN SC1.ExpirationDate IS NULL THEN '' ELSE ISNULL(F1.FinInstCode, '') END AS CreditProvider
    , CASE WHEN SC1.ExpirationDate IS NULL THEN '' ELSE ISNULL(C1.CreditEnhancementCode, '') END AS CreditType
    , SC1.ExpirationDate AS CreditExpirationDate
    , SC1.RefNum AS RefNumber
FROM dbo.SecurityCreditEnhancementProvider SC1
LEFT JOIN dbo.FinInst F1
    ON SC1.CreditProviderID = F1.FinInstID 
LEFT JOIN dbo.LUCreditEnhancement C1
    ON SC1.CreditEnhancementID = C1.CreditEnhancementID 
LEFT JOIN dbo.Security S 
    ON S.SecID = SC1.SecID 
LEFT OUTER JOIN dbo.FinInst F2 
    ON S.TrusteeID = F2.FinInstID
LEFT OUTER JOIN dbo.FinInst RA 
    ON S.RemarketingAgentID = RA.FinInstID
WHERE (C1.CreditEnhancementCode = 'LOC' OR C1.CreditEnhancementCode = 'LIQUIDITY' )
    AND (S.ActiveFlag = 'A') 
    AND (S.SecTypeID NOT IN (4, 7))
ORDER BY CreditExpirationDate