{"record":{"id":"78e754b5982e6e5d","repo":"louislam/uptime-kuma","slug":"multiple-values-were-found-expected-only-one-valu","errorCode":null,"errorMessage":"Multiple values were found, expected only one value","messagePattern":"Multiple values were found, expected only one value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/mssql.js","lineNumber":109,"sourceCode":"     * @param {string} connectionString The database connection string\n     * @param {string} query The query to validate the database with\n     * @returns {Promise<any>} Single value from the first column of the first row\n     */\n    async mssqlQuerySingleValue(connectionString, query) {\n        let pool;\n        try {\n            pool = new mssql.ConnectionPool(connectionString);\n            await pool.connect();\n            const result = await pool.request().query(query);\n\n            // Check if we have results\n            if (!result.recordset || result.recordset.length === 0) {\n                throw new Error(\"Query returned no results\");\n            }\n\n            // Check if we have multiple rows\n            if (result.recordset.length > 1) {\n                throw new Error(\"Multiple values were found, expected only one value\");\n            }\n\n            const firstRow = result.recordset[0];\n            const columnNames = Object.keys(firstRow);\n\n            // Check if we have multiple columns\n            if (columnNames.length > 1) {\n                throw new Error(\"Multiple columns were found, expected only one value\");\n            }\n\n            // Return the single value from the first (and only) column\n            return firstRow[columnNames[0]];\n        } catch (err) {\n            log.debug(\"sqlserver\", \"Error caught in the query execution.\", err.message);\n            throw err;\n        } finally {\n            if (pool) {\n                await pool.close();","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/mssql.js#L91-L127","documentation":"Thrown by mssqlQuerySingleValue when the query returns more than one row. With conditions enabled the monitor needs exactly one scalar; multiple rows are ambiguous and rejected. Detection happens before column-count validation, so this fires first whenever both conditions are violated.","triggerScenarios":"monitor.conditions non-empty, result.recordset.length > 1. Typical of SELECT col FROM table without TOP/LIMIT, missing WHERE, or a join that fans out rows.","commonSituations":"Used SELECT * / SELECT col FROM large table; forgot TOP 1; conditions enabled on a query originally written to return a row count; join produced a cartesian product.","solutions":["Add TOP 1 (or TOP (1)) plus a deterministic ORDER BY to pick a single row.","Add or tighten a WHERE clause so at most one row matches.","Replace with an aggregate (MAX/MIN/SUM) that collapses to one scalar.","Confirm conditions are actually needed; if not, disable them to use the row-count path."],"exampleFix":"-- before: SELECT cpu_pct FROM metrics ORDER BY ts DESC;   (many rows)\n-- after:  SELECT TOP 1 cpu_pct FROM metrics ORDER BY ts DESC;","handlingStrategy":"validation","validationCode":"async function rowCount(connStr, query) {\n  const pool = new mssql.ConnectionPool(connStr); await pool.connect();\n  const r = await pool.request().query(query); await pool.close(); return r.recordset?.length ?? 0;\n}","typeGuard":"function isSingleRow(r) { return r?.recordset?.length === 1; }","tryCatchPattern":null,"preventionTips":["Add TOP 1 with a deterministic ORDER BY to any query used with conditions.","Prefer aggregates (MAX/MIN/SUM) that collapse to one row.","Run the query in SSMS before enabling the monitor."],"tags":["mssql","sqlserver","sql","multiple-results","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}