无法在VBA excel宏中运行多个左连接。 [英] Unable to run multiple left join in VBA excel macro.
问题描述
大家好,我正试图在Excem VBA宏编辑器中使用两个左连接运行此查询。由于语法错误,我无法获得结果。但是,如果我使用1个连接运行,那么它可以工作...请帮助
这里是编码:
工作表("dept_cm")。范围(") A1")。QueryTable.Sql =" select s.organization_id,s.organization_code," &安培; _
"s.inventory_item_id,s.part_number,d.dwsf_dept_wsf as dept_code" &安培; _
"i.category_set_name,i.segment1 as category_set,s.planner_code," &安培; _
"s.fixed_lead_time,s.variable_lead_time,s.preprocessing_lead_time,s.postprocessing_lead_time," &安培; _
"s.full_lead_time AS PROCESSING_LT,s.cum_manufacturing_lead_time,s.cumulative_total_lead_time," &安培; _
"s.atp_flag_name,s.atp_components_flag_name,s.atp_rule_name,s.release_time_fence_code_name,s.release_time_fence_days," &安培; _
"s.item_type_name,s.mrp_planning_code_name,s.planning_time_fence_code_name,s.planning_time_fence_days" &安培; _
"from((vMTL_system_items s left outer join vMTL_item_categories_all i ON i.inventory_item_id = s.inventory_item_id and i.organization_id = s.organization_id and i.category_set_id = 176)"& _
" ;左外连接vMTL_item_categories_all_xtab d ON i.inventory_item_id = d.inventory_item_id和i.organization_id = d.organization_id)" &安培; _
"其中s.organization_code ='F03'和(s.planner_code,如'EPSG%'或s.planner_code,如'EMT%')和s.inventory_item_status_code ='Production'and s.planning_make_buy_code_name ='购买'"
问题出在sql查询中。
在 d.dwsf_dept_wsf之后作为dept_code 应该有分号,因为你的sql查询没有运行。
通过在 d.dwsf_dept_wsf之后添加分号作为dept_code来更新你的SQL查询。
工作表("dept_cm")。范围(") A1")。QueryTable.Sql =" select s.organization_id,s.organization_code," &安培; _
"s.inventory_item_id,s.part_number, d.dwsf_dept_wsf as dept_code" &安培; _
"i.category_set_name ,i.segment1 as category_set,s.planner_code," &安培; _
"s.fixed_lead_time,s.variable_lead_time,s.preprocessing_lead_time,s.postprocessing_lead_time," &安培; _
"s.full_lead_time AS PROCESSING_LT,s.cum_manufacturing_lead_time,s.cumulative_total_lead_time," &安培; _
"s.atp_flag_name,s.atp_components_flag_name,s.atp_rule_name,s.release_time_fence_code_name,s.release_time_fence_days," &安培; _
"s.item_type_name,s.mrp_planning_code_name,s.planning_time_fence_code_name,s.planning_time_fence_days" &安培; _
"from((vMTL_system_items s left outer join vMTL_item_categories_all i ON i.inventory_item_id = s.inventory_item_id and i.organization_id = s.organization_id and i.category_set_id = 176)"& _
" ;左外连接vMTL_item_categories_all_xtab d ON i.inventory_item_id = d.inventory_item_id和i.organization_id = d.organization_id)" &安培; _
"其中s.organization_code ='F03'和(s.planner_code,如'EPSG%'或s.planner_code,如'EMT%')和s.inventory_item_status_code ='Production'and s.planning_make_buy_code_name ='购买""
hi ALL,
i'm trying to run this query with two left joins in Excem VBA Macro editor..i'm not able to get the result because of syntax error. however, if i run with 1 join, then it works...please help
here is the coding:
Worksheets("dept_cm").Range("A1").QueryTable.Sql = "select s.organization_id,s.organization_code," & _
"s.inventory_item_id , s.part_number, d.dwsf_dept_wsf as dept_code" & _
"i.category_set_name,i.segment1 as category_set,s.planner_code," & _
"s.fixed_lead_time,s.variable_lead_time,s.preprocessing_lead_time,s.postprocessing_lead_time," & _
"s.full_lead_time AS PROCESSING_LT,s.cum_manufacturing_lead_time,s.cumulative_total_lead_time," & _
"s.atp_flag_name,s.atp_components_flag_name,s.atp_rule_name,s.release_time_fence_code_name,s.release_time_fence_days," & _
"s.item_type_name,s.mrp_planning_code_name,s.planning_time_fence_code_name,s.planning_time_fence_days " & _
"from ((vMTL_system_items s left outer join vMTL_item_categories_all i ON i.inventory_item_id=s.inventory_item_id and i.organization_id=s.organization_id and i.category_set_id=176)" & _
"left outer join vMTL_item_categories_all_xtab d ON i.inventory_item_id=d.inventory_item_id and i.organization_id=d.organization_id)" & _
"where s.organization_code='F03' and (s.planner_code like 'EPSG%' or s.planner_code like 'EMT%') and s.inventory_item_status_code ='Production'and s.planning_make_buy_code_name='Buy'"
The problem is in sql query.
After d.dwsf_dept_wsf as dept_code there should be semicolon, due to that your sql query is not running.
Update you sql query by putting semicolon after d.dwsf_dept_wsf as dept_code, .
Worksheets("dept_cm").Range("A1").QueryTable.Sql = "select s.organization_id,s.organization_code," & _
"s.inventory_item_id , s.part_number, d.dwsf_dept_wsf as dept_code" & _
"i.category_set_name ,i.segment1 as category_set,s.planner_code," & _
"s.fixed_lead_time,s.variable_lead_time,s.preprocessing_lead_time,s.postprocessing_lead_time," & _
"s.full_lead_time AS PROCESSING_LT,s.cum_manufacturing_lead_time,s.cumulative_total_lead_time," & _
"s.atp_flag_name,s.atp_components_flag_name,s.atp_rule_name,s.release_time_fence_code_name,s.release_time_fence_days," & _
"s.item_type_name,s.mrp_planning_code_name,s.planning_time_fence_code_name,s.planning_time_fence_days " & _
"from ((vMTL_system_items s left outer join vMTL_item_categories_all i ON i.inventory_item_id=s.inventory_item_id and i.organization_id=s.organization_id and i.category_set_id=176)" & _
"left outer join vMTL_item_categories_all_xtab d ON i.inventory_item_id=d.inventory_item_id and i.organization_id=d.organization_id)" & _
"where s.organization_code='F03' and (s.planner_code like 'EPSG%' or s.planner_code like 'EMT%') and s.inventory_item_status_code ='Production'and s.planning_make_buy_code_name='Buy'"
这篇关于无法在VBA excel宏中运行多个左连接。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!