Множественное внешнее соединение - PullRequest
1 голос
/ 08 декабря 2010

Я действительно устал от доступа и его странного синтаксиса SQL, я просмотрел Google и StackOverflow, я нашел подсказки, но мне не удалось заставить работать мой большой запрос ... У меня просто несколько левых внешних объединенийчто я не могу договориться в скобках, чтобы он был принят этим проклятым Access ...

Не могли бы вы дать мне подсказку, что не так с моими объединениями?Почему access жалуется на: «JOIN SYNTAX error»

Заранее большое спасибо!

Милуд

SELECT ORDR.*, ITEM.*, ERAS.*, MAPP.New, KUMV.*
FROM ((GEN_ORDERS AS ORDR)
LEFT OUTER JOIN 
(    
(SELECT concat,ORDER_NUM, ConTY1 AS CT, ConValue1 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY2 AS CT, ConValue2 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY3 AS CT, ConValue3 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY4 AS CT, ConValue4 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY5 AS CT, ConValue5 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY6 AS CT, ConValue6 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY7 AS CT, ConValue7 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY8 AS CT, ConValue8 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY9 AS CT, ConValue9 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY10 AS CT, ConValue10 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY11 AS CT, ConValue11 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY12 AS CT, ConValue12 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY13 AS CT, ConValue13 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY14 AS CT, ConValue14 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY15 AS CT, ConValue15 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY16 AS CT, ConValue16 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY17 AS CT, ConValue17 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY18 AS CT, ConValue18 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY19 AS CT, ConValue19 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY20 AS CT, ConValue20 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY21 AS CT, ConValue21 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY22 AS CT, ConValue22 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY23 AS CT, ConValue23 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY24 AS CT, ConValue24 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY25 AS CT, ConValue25 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY26 AS CT, ConValue26 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY27 AS CT, ConValue27 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY28 AS CT, ConValue28 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY29 AS CT, ConValue29 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY30 AS CT, ConValue30 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY31 AS CT, ConValue31 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY32 AS CT, ConValue32 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY33 AS CT, ConValue33 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY34 AS CT, ConValue34 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY35 AS CT, ConValue35 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY36 AS CT, ConValue36 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY37 AS CT, ConValue37 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY38 AS CT, ConValue38 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY39 AS CT, ConValue39 AS CV FROM GEN_ITEMS UNION ALL
SELECT concat,ORDER_NUM, ConTY409 AS CT, ConValue40 AS CV FROM GEN_ITEMS) AS ITEM)
ON ORDR.ORDER_NUM = ITEM.ORDER_NUM
)
LEFT OUTER JOIN GEN_ERASALES AS ERAS ON ITEM.concat = ERAS.concat
LEFT OUTER JOIN MAPPING AS MAPP ON ITEM.CT = MAPP.Old
LEFT OUTER JOIN GEN_KUMV KUMV ON ERAS.DOCCOND = KUMV.KNUMV AND MAPP.New = KUMV.KSCHL

1 Ответ

1 голос
/ 08 декабря 2010

Доступ не имеет левого внешнего соединения, только левое соединение. Вам нужны круглые скобки для каждого соединения, и вы не можете иметь это И:

SELECT ORDR.*, ITEM.*, ERAS.*, MAPP.New, KUMV.*
FROM (((GEN_ORDERS AS ORDR
LEFT  JOIN 

(.... Union ....) As Item
 ON ORDR.ORDER_NUM = ITEM.ORDER_NUM)


LEFT  JOIN GEN_ERASALES AS ERAS ON ITEM.concat = ERAS.concat)
LEFT  JOIN MAPPING AS MAPP ON ITEM.CT = MAPP.Old)
LEFT  JOIN GEN_KUMV KUMV ON ERAS.DOCCOND = KUMV.KNUMV 

Вы можете использовать подзапрос или ГДЕ для AND MAPP.New = KUMV.KSCHL, в зависимости от ваших требований.

EDIT Я должен добавить, что Access будет принимать AND в соединениях, но в этом случае это приводит к неоднозначным внешним соединениям, поэтому необходима некоторая перестановка.

...