views:

39

answers:

2

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?
+1  A: 

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.

Michael Petrotta
+1  A: 

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
Mitch Wheat
no doubt about that....
Stefan
just trying sqlstr.Replace("RIGHT JOIN", "RIGHT OUTER JOIN").Replace("(", "").Replace(")", "") and it seems to be getter better
Stefan