{"record":{"id":"a4fe1acd80752690","repo":"louislam/uptime-kuma","slug":"query-returned-no-results","errorCode":null,"errorMessage":"Query returned no results","messagePattern":"Query returned no results","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/mssql.js","lineNumber":104,"sourceCode":"        }\n    }\n\n    /**\n     * Run a query on MSSQL server expecting a single value result\n     * @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) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/mssql.js#L86-L122","documentation":"Thrown by MssqlMonitorType.mssqlQuerySingleValue when the query's recordset is empty (or absent). This path runs only when conditions are enabled, because the monitor expects a single scalar to feed the condition evaluator. An empty result means there is no value to compare, so the check fails before conditions are evaluated.","triggerScenarios":"monitor.conditions is non-empty, mssqlQuerySingleValue runs the query, result.recordset is falsy or result.recordset.length === 0. Typical when a WHERE clause filters every row, an aggregate finds no rows (e.g. MAX over empty set becomes NULL row only without GROUP BY in some setups), or the wrong database/table is queried.","commonSituations":"WHERE clause too restrictive (date filter, tenant id); table renamed/migrated so query finds nothing; query written for the legacy row-count path but conditions turned on; environment-specific data missing in the monitored DB.","solutions":["Run the query in SSMS against the monitored database and confirm it returns exactly one row with one column.","If empty results are legitimate, restructure the query to always return a scalar (e.g. SELECT COUNT(*) or ISNULL((SELECT ...),0)).","Loosen or correct the WHERE clause so the expected row exists.","Turn conditions off if you only need connection/row-count semantics."],"exampleFix":"-- before: SELECT balance FROM accounts WHERE id=@id   (id missing -> 0 rows)\n-- after:  SELECT ISNULL((SELECT balance FROM accounts WHERE id=@id), -1);","handlingStrategy":"validation","validationCode":"async function assertSingleValueQuery(connStr, query) {\n  const pool = new mssql.ConnectionPool(connStr); await pool.connect();\n  const r = await pool.request().query(query); await pool.close();\n  if (!r.recordset || r.recordset.length === 0) throw new Error('query returns 0 rows');\n  if (r.recordset.length > 1) throw new Error('query returns >1 row');\n  if (Object.keys(r.recordset[0]).length > 1) throw new Error('query returns >1 column');\n  return r.recordset[0][Object.keys(r.recordset[0])[0]];\n}","typeGuard":"function isSingleValueRecordset(r) { return r?.recordset?.length === 1 && Object.keys(r.recordset[0]).length === 1; }","tryCatchPattern":null,"preventionTips":["Before enabling conditions, run the query and assert it returns 1 row x 1 column.","Use ISNULL/COALESCE/aggregates so the query always returns a scalar.","Keep conditions off if you only need connection checks."],"tags":["mssql","sqlserver","sql","empty-result","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}