{"record":{"id":"ddcc8c454c7ccea3","repo":"louislam/uptime-kuma","slug":"query-result-did-not-meet-the-specified-conditions","errorCode":null,"errorMessage":"Query result did not meet the specified conditions (${result})","messagePattern":"Query result did not meet the specified conditions \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/mssql.js","lineNumber":39,"sourceCode":"        // No query provided by user, use SELECT 1\n        if (!query || (typeof query === \"string\" && query.trim() === \"\")) {\n            query = \"SELECT 1\";\n        }\n\n        const conditions = monitor.conditions ? ConditionExpressionGroup.fromMonitor(monitor) : null;\n        const hasConditions = conditions && conditions.children && conditions.children.length > 0;\n\n        const startTime = dayjs().valueOf();\n        try {\n            if (hasConditions) {\n                // When conditions are enabled, expect a single value result\n                const result = await this.mssqlQuerySingleValue(monitor.databaseConnectionString, query);\n                heartbeat.ping = dayjs().valueOf() - startTime;\n\n                const conditionsResult = evaluateExpressionGroup(conditions, { result: String(result) });\n\n                if (!conditionsResult) {\n                    throw new Error(`Query result did not meet the specified conditions (${result})`);\n                }\n\n                heartbeat.status = UP;\n                heartbeat.msg = \"Query did meet specified conditions\";\n            } else {\n                // Backwards compatible: just check connection and return row count\n                const result = await this.mssqlQuery(monitor.databaseConnectionString, query);\n                heartbeat.ping = dayjs().valueOf() - startTime;\n                heartbeat.status = UP;\n                heartbeat.msg = result;\n            }\n        } catch (error) {\n            heartbeat.ping = dayjs().valueOf() - startTime;\n            // Re-throw condition errors as-is, wrap database errors\n            if (error.message.includes(\"did not meet the specified conditions\")) {\n                throw error;\n            }\n            throw new Error(`Database connection/query failed: ${error.message}`);","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/mssql.js#L21-L57","documentation":"Thrown by MssqlMonitorType.check when conditions are configured and the single-value query result, coerced to String, does not satisfy evaluateExpressionGroup({result: String(result)}). The condition system is given exactly one variable named 'result', so any condition referencing another variable will always be false.","triggerScenarios":"monitor.conditions has children, mssqlQuerySingleValue returns a scalar, and evaluateExpressionGroup over {result: String(result)} is false. Common when the condition expects a numeric operator but 'result' is a stringified value like '1.0000', or when threshold/operator semantics do not match the actual value.","commonSituations":"Condition uses operator '==' against a formatted number ('1' vs '1.00'); condition references a variable other than 'result'; SQL returns a value outside the expected range; String() coercion of dates/decimals differs from the literal in the condition.","solutions":["Run the exact query in SSMS/Azure Data Studio and note the precise scalar value (including decimals/formatting) the monitor will see.","Ensure the condition references the 'result' variable; no other variable is exposed on this monitor type.","Use numeric operators (>, <, between) rather than '==' when the column is numeric, to avoid String() formatting mismatches like '1' vs '1.00'.","Cast/round the value in the SELECT (e.g. SELECT CAST(col AS int) or ROUND(col,2)) so it matches the condition literal deterministically."],"exampleFix":"-- before: SELECT AVG(price) FROM orders   (returns 12.340000)\n-- condition: result == '12.34'  -> fails\n-- after:\nSELECT ROUND(AVG(price),2) FROM orders;\n-- condition: result >= 12 and result <= 13","handlingStrategy":"try-catch","validationCode":"const scalar = await mssqlMonitor.mssqlQuerySingleValue(connStr, query);\nconst ok = evaluateExpressionGroup(group, { result: String(scalar) });\nif (!ok) { /* adjust query or condition before enabling */ }","typeGuard":"function conditionUsesResultVar(group) { return group.children.every(c => c.variable === 'result'); }","tryCatchPattern":"try { await mssqlMonitor.check(monitor, heartbeat, server); }\ncatch (e) { if (/did not meet the specified conditions/.test(e.message)) { heartbeat.status = DOWN; heartbeat.msg = e.message; } else throw e; }","preventionTips":["Always SELECT a single, deterministic scalar and round/cast it.","Reference only the 'result' variable in MSSQL conditions.","Use numeric range operators for numeric columns."],"tags":["mssql","sqlserver","conditions","database","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}