A custom report running on a local server here that has MS Sql Server can run this command fine. Im not an expert and this query is probably a bad hodge podge of code, but it worked.
Now the database has been moved into the cloud and an error I get when I have a syntax error trying to figure this out suggests its a MariaDb database.
When I try to run this code that currently works on T-Sql, I get this error:
Parameter index 0 is invalid when only 0 parameters are defined
Here is the query.
/* 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
Any ideas what is causing this error?
Thanks.
4
I think the question mark in [On Hold? / Comments] might be interpreted as a parameter place holder? You are using square brackets as a quote character for column names with special characters; MariaDB doc says back-quote or double-quote is to be used ; see:
https://mariadb.com/kb/en/identifier-names/