[英]Access 2010 Query Syntax error
(1) Access 數據庫被用作連接到 2 個 Teradata 數據庫的方式 (2) 目前它有 6 個鏈接表到 2 個 Teradata 數據庫 (3) 對我來說它是 Access Query 還是 pass-通過查詢到 Teradata (4) 目標是在 Excel 宏中放入一些內容,該宏將查詢 2 個 Teradata 數據庫並返回一些將包含在宏中的信息
我正在嘗試使用適用於 Teradata 的 SQL 在 Access 中創建 SQL 查詢。 當我嘗試運行查詢時,我收到錯誤消息(FROM 子句中的語法錯誤)並且突出顯示了第一個連接。 我以前在 Access 中編寫過查詢,但沒有這么復雜。 我們正在使用 Access 2010。對語法錯誤的任何建議將不勝感激。 謝謝您的幫助.......
select veh_mgmt_csr.cst_bo_item.veh_lgcy_nbr as unit, veh_mgmt_csr.cst_bo_item.veh_odmtr_qty as mileage, veh_mgmt_csr.rm_cust_mast.upp_lgl_cust_nam as cust_legal_name, veh_mgmt_csr_rv.cst_address.addr_st_nam as address,
veh_mgmt_csr_rv.cst_address.addr_cty_nam as city, veh_mgmt_csr_rv.cst_address.addr_postl_cde as zip, veh_mgmt_csr_rv.cst_address.stprov_cde as state, veh_mgmt_csr_rv.cst_address.cntry_iso_cde as country, veh_mgmt_csr_rv.cst_address.addr_phn_nbr as location_phone, e.contact_name, e.contact_phone
from veh_mgmt_csr.cst_buyer_order
Join veh_mgmt_csr.cst_bo_item on veh_mgmt_csr.cst_buyer_order.bo_id = veh_mgmt_csr.cst_bo_item.bo_id and veh_mgmt_csr.cst_bo_item.veh_invy_stat_dsc = 'SOLD'
Join veh_mgmt_csr.rm_cust_mast on veh_mgmt_csr.cst_buyer_order.rm_cust_id = veh_mgmt_csr.rm_cust_mast.rm_cust_id
Join VEH_MGMT_CSR_RV.cst_address on veh_mgmt_csr.rm_cust_mast.prim_addr_id = veh_mgmt_csr_rv.cst_address.addr_id and veh_mgmt_csr_rv.cst_address.record_status = 'A'
left join (select veh_mgmt_csr.cst_buyer_order.e_o_id cust_nbr,trim(veh_mgmt_csr.cst_individual.indiv_upp_frst_nam) || ' ' || trim(veh_mgmt_csr.cst_individual.indiv_upp_last_nam) contact_name,
VEH_MGMT_CSR_RV.CST_PHONE_NBR.phn_nbr contact_phone from veh_mgmt_csr.cst_e_o_cntct
left join veh_mgmt_csr.cst_individual on veh_mgmt_csr.cst_e_o_cntct.indiv_id = veh_mgmt_csr.cst_individual.indiv_id
left join VEH_MGMT_CSR_RV.CST_PHONE_NBR on veh_mgmt_csr.cst_e_o_cntct.indiv_id = VEH_MGMT_CSR_RV.CST_PHONE_NBR.indiv_id and VEH_MGMT_CSR_RV.CST_PHONE_NBR.prim_phn_ind = 1
qualify rank() over (partition by veh_mgmt_csr.cst_e_o_cntct.e_o_id order by contact_name asc) = 1) e on veh_mgmt_csr.rm_cust_mast.rm_cust_id = e.cust_nbr
where veh_mgmt_csr.cst_individual.veh_lgcy_nbr = '8B5RG1'
and veh_mgmt_csr.cst_e_o_cntct.cntry_iso_cde in ('US','CA')
and extract(year from veh_mgmt_csr.cst_e_o_cntct.bo_dte) = 2017
作為 SQL 的初學者,請注意,盡管包括 MS Access 和 Teradata 在內的大多數 RDBMS 都可以運行 ANSI-SQL(基本的標准 DDL/DML 語句),但幾乎沒有兩個 RDBMS 共享相同的方言 (ANSI-plus)。 每個人都有自己的風格和特定的方法。
此外,請注意 MS Access 有兩個方面:1) GUI .exe 應用程序和 2) 數據庫引擎(ACE/JET 數據庫引擎)。 隨着時間的推移,它被混為一談,但事實並非如此。 看到這個元帖子。 以前的 .exe 應用程序默認連接到默認數據庫引擎,但可以為其他后端(如 Teradata)切換此默認設置。
但是,前端 GUI 和后端數據庫之間的連接方法(即鏈接表、傳遞查詢、應用程序代碼)將因所使用的 SQL 方言而異。
您可能試圖在 MS Access 鏈接表上運行 Teradata SQL,因此違反了 #1 並導致語法錯誤。 如下所示,使用適當的縮進,您嘗試的查詢中有幾種不兼容的語法:
JOIN
而是需要INNER
、 LEFT
或RIGHT
(沒有OUTER
);JOIN
子句中使用表對時,MS Access 都需要括號;RANK() OVER...
;&
連接而不是雙管道||
並使用Year()
而不是extract(year ...)
; 並且不使用qualify
,可能嚴格來說是一種Teradata 方法;AS
作為列別名,例如contact_name和contact_phone 。SQL
SELECT veh_mgmt_csr.cst_bo_item.veh_lgcy_nbr AS unit,
veh_mgmt_csr.cst_bo_item.veh_odmtr_qty AS mileage,
veh_mgmt_csr.rm_cust_mast.upp_lgl_cust_nam AS cust_legal_name,
veh_mgmt_csr_rv.cst_address.addr_st_nam AS address,
veh_mgmt_csr_rv.cst_address.addr_cty_nam AS city,
veh_mgmt_csr_rv.cst_address.addr_postl_cde AS zip,
veh_mgmt_csr_rv.cst_address.stprov_cde AS state,
veh_mgmt_csr_rv.cst_address.cntry_iso_cde AS country,
veh_mgmt_csr_rv.cst_address.addr_phn_nbr AS location_phone,
e.contact_name,
e.contact_phone
FROM veh_mgmt_csr.cst_buyer_order
JOIN veh_mgmt_csr.cst_bo_item
ON veh_mgmt_csr.cst_buyer_order.bo_id = veh_mgmt_csr.cst_bo_item.bo_id
AND veh_mgmt_csr.cst_bo_item.veh_invy_stat_dsc = 'SOLD'
JOIN veh_mgmt_csr.rm_cust_mast
ON veh_mgmt_csr.cst_buyer_order.rm_cust_id = veh_mgmt_csr.rm_cust_mast.rm_cust_id
JOIN veh_mgmt_csr_rv.cst_address
ON veh_mgmt_csr.rm_cust_mast.prim_addr_id = veh_mgmt_csr_rv.cst_address.addr_id
AND veh_mgmt_csr_rv.cst_address.record_status = 'A'
LEFT JOIN
(
SELECT veh_mgmt_csr.cst_buyer_order.e_o_id cust_nbr,
Trim(veh_mgmt_csr.cst_individual.indiv_upp_frst_nam)
|| ' ' ||
Trim(veh_mgmt_csr.cst_individual.indiv_upp_last_nam) contact_name,
veh_mgmt_csr_rv.cst_phone_nbr.phn_nbr contact_phone
FROM veh_mgmt_csr.cst_e_o_cntct
LEFT JOIN veh_mgmt_csr.cst_individual
ON veh_mgmt_csr.cst_e_o_cntct.indiv_id = veh_mgmt_csr.cst_individual.indiv_id
LEFT JOIN veh_mgmt_csr_rv.cst_phone_nbr
ON veh_mgmt_csr.cst_e_o_cntct.indiv_id = veh_mgmt_csr_rv.cst_phone_nbr.indiv_id
AND veh_mgmt_csr_rv.cst_phone_nbr.prim_phn_ind = 1
qualify rank() OVER (partition BY veh_mgmt_csr.cst_e_o_cntct.e_o_id
ORDER BY contact_name ASC) = 1) e
ON veh_mgmt_csr.rm_cust_mast.rm_cust_id = e.cust_nbr
WHERE veh_mgmt_csr.cst_individual.veh_lgcy_nbr = '8B5RG1'
AND veh_mgmt_csr.cst_e_o_cntct.cntry_iso_cde IN ('US','CA')
AND extract(year FROM veh_mgmt_csr.cst_e_o_cntct.bo_dte) = 2017;
根據您的更新執行以下操作:
SELECT * INTO myAccessTable FROM myTeradataPassThroughQuery
) 以將 Teradata 結果移動到 Access 本地表中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.