-2

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

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 }

谢谢大家的帮助。

4

1 回答 1

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
于 2012-05-30T22:24:35.380 回答