For easier reading, here’s the query:
DECLARE @downtimeDivisor AS INT = 1
IF :downtimeFormat = 'hour' OR :downtimeFormat = 'hours'
SET @downtimeDivisor = 3600;
ELSE IF :downtimeFormat = 'minute' OR :downtimeFormat = 'minutes'
SET @downtimeDivisor = 60;
SELECT TOP(:limit)
stops.first_fault AS fault,
COUNT(*) AS count,
(SUM(stops.stop_duration) / @downtimeDivisor) AS downtime
FROM stop_history stops
WHERE stops.first_fault_time BETWEEN :startDate AND :endDate
AND stops.first_fault NOT IN {hiddenFaults}
GROUP BY stops.first_fault
ORDER BY count DESC
Shown above is a screenshot of my Query Binding setup. The Error I’m seeing is “Syntax Error on Token: ‘End of Expression’ (Line 0, Character 0)” and I’m completely stumped as to what’s causing it.
Queries with these same startDate
, endDate
, limit
and hiddenFaults
parameters are being used elsewhere with no problem. The main difference here between all my other queries is the use of DECLARE
for local variables. Could that be causing a problem?
The more bizarre thing is that this query works just fine in the Named Queries query testing area, with manually provided parameters.