在具有 MS Sql Server 的本地服务器上运行的自定义报告可以正常运行此命令。我不是专家,这个查询可能是代码的糟糕大杂烩,但它有效。 现在数据库已移至云中,当我尝试解决此问题时遇到语法错误时收到的错误表明它是 MariaDb 数据库。 当我尝试运行当前在 T-Sql 上运行的代码时,我收到此错误:
仅定义0个参数时,参数索引0无效
这是查询。
/* Show the CURRENT LOCATIONS of all the jobs
Sorted by DueDates first, then by JobNo
*/
Select OrderDet.DueDate, Orders.CustDesc, Orders.PONum,
CASE
WHEN OrderDet.QtyOrdered > 0 THEN STR(OrderDet.QtyOrdered)
WHEN OrderDet.QtyToStock > 0 THEN 'For Stock (' + STR(OrderDet.QtyToStock) + ')'
END AS [QTY ORDERED],
OrderRouting.JobNo, OrderRouting.PartNo,
CASE
WHEN OrderRouting.VendCode IS NOT NULL THEN '@ ' + OrderRouting.VendCode
WHEN StepCount = 1 AND OrderRouting.Status = 'Finished' THEN 'SHIPPING'
WHEN Online.JobNo IS NOT NULL AND Online.StepNo IS NOT NULL THEN WorkCntr.ShortName /*Display WrkCntr current employee is clocked into*/
ELSE OrderRouting.WorkCntr
END AS [Current Location], OrderRouting.OperCode,
CASE
WHEN Online.JobNo IS NOT NULL AND Online.StepNo IS NOT NULL THEN 'Clocked In By - ' + Online.EmplCode
Else ''
END AS [Current Status],
CASE
WHEN OrderDet.JobOnHold = 'Y' THEN 'On Hold'
WHEN TimeTicketDetails.Comments IS NOT NULL THEN TimeTicketDetails.Comments
ELSE ''
END AS [On Hold? / Comments], OrderRouting.StepNo
From OrderRouting
/* Create an intermediate Table for 'StepCount' to be used in main query */
JOIN ( Select ROW_NUMBER() OVER (PARTITION BY OrderRouting.JobNo ORDER BY OrderRouting.StepNo DESC) AS [StepCount], OrderRouting.JobNo, OrderRouting.StepNo
From OrderRouting
Where OrderRouting.JobNo IS NOT NULL AND OrderRouting.JobNo != '' ) Step_Count
ON Step_Count.JobNo = OrderRouting.JobNo AND Step_Count.StepNo = OrderRouting.StepNo
INNER JOIN OrderDet on OrderDet.JobNo = OrderRouting.JobNo
INNER JOIN Orders ON Orders.OrderNo = OrderRouting.OrderNo
LEFT OUTER JOIN Online ON Online.JobNo = OrderRouting.JobNo
LEFT OUTER JOIN WorkCntr ON WorkCntr.WorkCntr = Online.WorkCntr
LEFT OUTER JOIN (
Select TimeTicketDet.* From TimeTicketDet
JOIN (
Select JobNo, StepNo, MAX(TimeTicketDet_ID) as [LastID] From TimeTicketDet
GROUP BY JobNo, StepNo
) tt1 ON tt1.JobNo = TimeTicketDet.JobNo AND tt1.LastID = TimeTicketDet.TimeTicketDet_ID
) TimeTicketDetails ON TimeTicketDetails.JobNo = OrderRouting.JobNo AND TimeTicketDetails.StepNo = OrderRouting.StepNo
WHERE OrderDet.Status = 'Open' AND
(OrderRouting.Status = 'Current' OR (OrderRouting.Status = 'Finished' AND Step_Count.StepCount = 1))
Order By DueDate,
OrderRouting.OrderNo,
OrderRouting.JobNo,
OrderRouting.StepNo
有什么想法导致此错误吗? 谢谢。
我认为【暂停? /评论]可能会被解释为参数占位符?您使用方括号作为带有特殊字符的列名称的引号字符; MariaDB 文档说要使用反引号或双引号;看: https://mariadb.com/kb/en/identifier-names/