场景:我正在 Excel 中构建一个报告来计算佣金。这是基于上个月的发票。我创建了以下tsql
查询并使用MSQuery
. 我测试了查询,它运行良好,直到我将Where语句更改为使用参数"?"
,所以我可以,然后我收到以下错误:
Incorrect Syntax near the keyword `'SELECT'`
这是查询:
SELECT v_rpt_Invoices.Invoice_Number, v_rpt_Invoices.Territory, v_rpt_Company.Account_Nbr, v_rpt_Invoices.Company_Name, v_rpt_Invoices.Date_Invoice,
v_rpt_Invoices.Location, v_rpt_Invoices.TicketNbr, v_rpt_Invoices.Project_ID, v_rpt_Invoices.Invoice_Type, v_rpt_Invoices.Status_Description,
CASE WHEN TicketNbr <> 0 THEN 'Service Ticket' WHEN Project_ID IS NOT NULL THEN 'Project' ELSE 'Other' END AS Invoice_For,
CASE WHEN ticketNbr <> 0 THEN
(SELECT v_rpt_Service.Board_Name
FROM v_rpt_Service
WHERE v_rpt_Invoices.TicketNbr = v_rpt_Service.TicketNbr) WHEN Project_ID IS NOT NULL THEN Project_ID ELSE 'Other' END AS Service_Board_Project,
CASE WHEN TicketNbr <> 0 THEN
(SELECT Bill_Method
FROM SR_Service
WHERE v_rpt_Invoices.TicketNbr = SR_Service.SR_Service_RecID) WHEN project_id IS NOT NULL THEN
(SELECT PM_Billing_Method_ID
FROM PM_Project
WHERE v_rpt_Invoices.PM_Project_RecID = PM_Project.PM_Project_RecID) ELSE 'NONE' END AS BillingMethod, v_rpt_Invoices.Invoice_Amount,
CASE WHEN (TicketNbr <> 0 AND
(SELECT Bill_Method
FROM SR_Service
WHERE v_rpt_Invoices.TicketNbr = SR_Service.SR_Service_RecID) = 'A') THEN Invoice_Amount * 0.7 WHEN (TicketNbr <> 0 AND
(SELECT Bill_Method
FROM SR_Service
WHERE v_rpt_Invoices.TicketNbr = SR_Service.SR_Service_RecID) = 'F') THEN 0.01 WHEN (project_id IS NOT NULL AND
(SELECT PM_Billing_Method_ID
FROM PM_Project
WHERE v_rpt_Invoices.PM_Project_RecID = PM_Project.PM_Project_RecID) = 'A') THEN Invoice_Amount * 0.7 WHEN (project_id IS NOT NULL AND
(SELECT PM_Billing_Method_ID
FROM PM_Project
WHERE v_rpt_Invoices.PM_Project_RecID = PM_Project.PM_Project_RecID) = 'F') THEN 0.01 ELSE 0.00 END AS Cost
FROM v_rpt_Invoices INNER JOIN
v_rpt_Company ON v_rpt_Invoices.Company_RecID = v_rpt_Company.Company_RecID
**WHERE (v_rpt_Invoices.Date_Invoice >= ?)**
order by Territory, Invoice_For