1

this query:

SELECT sentmails.[VersandDatum], 
       sentmails.[DatumMailGeplant], 
       mailintervals.[Interval], 
       definitions.[Subject], 
       users.[Name], 
       sentmails.[MailArt], 
       Objekte.[Name], 
       sentmails.[Erledigt], 
       sentmails.[ID]
  FROM Objekte 
RIGHT JOIN (users RIGHT JOIN (definitions RIGHT JOIN (mailintervals RIGHT JOIN (sentmails) ON mailintervals.ID=sentmails.Intervall) ON definitions.ID=sentmails.Noti_ID) ON users.UID=sentmails.Funktion) ON Objekte.OId=sentmails.Objekt_ID

...works fine in ms access qbe, but in sql server it returns a "incorrect syntax near ')'" error. I'm really wondering why:

  • the joins need to be in brackets?
  • no more outer joins in sql server?
  • somewhere more brackets needed?

2 Answers 2

1

MS Access has a slightly different JOIN syntax. Use this instead:

SELECT 
    sentmails.[VersandDatum], 
    sentmails.[DatumMailGeplant], 
    mailintervals.[Interval], 
    definitions.[Subject], 
    users.[Name], 
    sentmails.[MailArt], 
    Objekte.[Name], 
    sentmails.[Erledigt], 
    sentmails.[ID]
FROM Objekte 
RIGHT JOIN sentmails ON Objekte.OId=sentmails.Objekt_ID
RIGHT JOIN definitions definitions.ID=sentmails.Noti_ID
RIGHT JOIN mailintervals ON mailintervals.ID=sentmails.Intervall
RIGHT JOIN users ON users.UID=sentmails.Funktion
Sign up to request clarification or add additional context in comments.

1 Comment

just trying sqlstr.Replace("RIGHT JOIN", "RIGHT OUTER JOIN").Replace("(", "").Replace(")", "") and it seems to be getter better
1

Your JOIN syntax is incorrect. You should be joining each table individually, without nested parentheses. You probably want something like:

SELECT sentmails.[VersandDatum]
    , sentmails.[DatumMailGeplant]
    , mailintervals.[Interval]
    , definitions.[Subject]
    , users.[Name]
    , sentmails.[MailArt]
    , Objekte.[Name]
    , sentmails.[Erledigt]
    , sentmails.[ID]
FROM Objekte
RIGHT JOIN sentmails ON Objekte.OId = sentmails.Objekt_ID
RIGHT JOIN users ON users.UID = sentmails.Funktion
RIGHT JOIN definitions ON definitions.ID = sentmails.Noti_ID
RIGHT JOIN mailintervals ON mailintervals.ID = sentmails.Intervall

Here's a starting point in MSDN.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.