-2

I'm trying to execute the following query for a Dataset:

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

When trying to run the query the error I get is " Error in FROM clause near: '{' . Unable to parse query. "

Any help to fix this issue would be most appreciated.

Thanks,

EDIT 1: This is what is looks like after query designer changes the code:

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 }

Thanks all for there help.

kingblazi
  • 23
  • 1
  • 6
  • 1
    to after second `LEFT OUTER JOIN`, just before `WHERE`. Read the error message; it's extremely clear. – Ken White May 30 '12 at 22:22
  • 1
    How to solve this yourself: Look at error message. See it talks about an error near `{`. Search your code for a `{`. Consider whether that looks right (hint - it doesn't). – AakashM May 31 '12 at 08:16
  • Thanks for your help, when I was trying to reformat the code around said segment, query designer kept putting it back in. Thats why I was asking for help. – kingblazi May 31 '12 at 12:51

1 Answers1

0

Formatting code in a case like this might be helpful. you had incorrect syntax in your FROM clause. I also updated the query to use JOIN Syntax on all tables instead of using commas between your tables.

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
Taryn
  • 242,637
  • 56
  • 362
  • 405