1

这个查询:

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

...在 ms access qbe 中工作正常,但在 sql server 中它返回“')' 附近的语法不正确”错误。我真的很想知道为什么:

  • 连接需要放在括号中吗?
  • sql server 中不再有外连接?
  • 需要更多括号的地方吗?
4

2 回答 2

1

你的JOIN语法不正确。您应该单独加入每个表,没有嵌套括号。你可能想要这样的东西:

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

这是 MSDN 的起点

于 2010-10-10T01:57:44.153 回答
1

MS Access 的 JOIN 语法略有不同。改用这个:

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
于 2010-10-10T02:00:07.583 回答