2013-09-30 48 views
0

表1 - 該表被完全從XLSX文件填充...將數據傳輸到另一個,一些關係列

enter image description here

表2和3 - 含有1-對決賽桌中的幾列進行1次引用。

enter image description here

表3 - 在上,我試圖讓填充前三表....

enter image description here

正如你可以看到,該表是明智的,有沒有愛因斯坦方程或轉換正在進行。以下是我已經嘗試過的代碼,不成功:

INSERT INTO att_oem_orders SELECT NULL, ost.om_or_po, (SELECT j.job_id FROM jobs j WHERE j.project_number = project_no), NULL, (SELECT ao.id FROM att_oem WHERE ao.item_no = item_no), ost.po_number, (SELECT ol.id FROM order_lsc WHERE STATUS = ol.line_status_code), ost.ordered_date, ost.shipment_date, NULL, NULL, ost.item_qty, NULL, NULL, NULL, NULL, ost.shipping_to, ost.tracking_number, ost.carrier) FROM oem_temp_sync WHERE ost.item_qty > 0 
+0

你是否嘗試明確列出你想要插入到att_oem_orders的列? (我假設Select語句有效) – AgRizzo

+0

'SELECT'語句很瘋狂。它要求提供表名,其中一些字段是多餘的,並且在幾個子查詢中給我「子查詢返回多於一行」。也許我需要以編程方式做這件事,因爲SQL正在把我的大腦變成醬汁。 – DevlshOne

回答

1

嘗試限制可能值的數量使用FIRST()像這樣投入到一個領域:

INSERT INTO att_oem_orders SELECT 
    NULL, 
    ost.om_or_po, 
    (SELECT FIRST(j.job_id) FROM jobs j WHERE j.project_number = project_no), 
    NULL, 
    (SELECT FIRST(ao.id) FROM att_oem WHERE ao.item_no = item_no), 
    ost.po_number, 
    (SELECT FIRST(ol.id) FROM order_lsc WHERE STATUS = ol.line_status_code), 
    ost.ordered_date, 
    ost.shipment_date, 
    NULL, 
    NULL, 
    ost.item_qty, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    ost.shipping_to, 
    ost.tracking_number, 
    ost.carrier 
FROM oem_temp_sync WHERE ost.item_qty > 0 

也似乎有一個額外的)就在從前

0

隨着每個人的一點點幫助,我發現了一些錯誤,並修復了一些子查詢。這裏是最終版本:

INSERT INTO att_oem_orders 
SELECT 
    NULL, 
    ost.om_or_po, 
    (SELECT 
     FIRST(j.id) 
    FROM 
     jobs j 
    WHERE j.project_number = ost.project_no), 
    NULL, 
    (SELECT 
     FIRST(ao.id) 
    FROM 
     att_oem ao 
    WHERE ao.item_no = ost.item_no), 
    ost.po_number, 
    (SELECT 
     FIRST(ol.id) 
    FROM 
     att_oem_lsc ol 
    WHERE ol.status = ost.line_status_code), 
    ost.ordered_date, 
    ost.shipment_date, 
    NULL, 
    NULL, 
    ost.item_qty, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    ost.ship_to, 
    ost.tracking_no, 
    ost.carrier 
FROM 
    oem_sync_temp ost 
WHERE ost.item_qty > 0 
相關問題