Browse Source

fix(nocodb): empty result for MSSQL

pull/4644/head
Wing-Kam Wong 2 years ago
parent
commit
4cef10222d
  1. 21
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

21
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts

@ -736,8 +736,27 @@ export default async function formulaQueryBuilderv2(
: pt.right.value === '' : pt.right.value === ''
: false : false
}) ${colAlias}`; }) ${colAlias}`;
} } else if (knex.clientType() === 'mssql') {
if (pt.operator === '=') {
if (pt.left.type === 'Literal' && pt.left.value === '') {
sql = `${right} IS NULL OR ${right} = ''`;
} else if (pt.right.type === 'Literal' && pt.right.value === '') {
sql = `${left} IS NULL OR ${left} = ''`;
}
} else if (pt.operator === '!=') {
if (pt.left.type === 'Literal' && pt.left.value === '') {
sql = `${right} IS NOT NULL AND ${right} != ''`;
} else if (pt.right.type === 'Literal' && pt.right.value === '') {
sql = `${left} IS NOT NULL AND ${left} != ''`;
}
}
if (prevBinaryOp !== 'AND' && prevBinaryOp !== 'OR') {
sql = `CASE WHEN ${sql} THEN 1 ELSE 0 END ${colAlias}`;
} else {
sql = `${sql} ${colAlias}`;
}
}
const query = knex.raw(sql); const query = knex.raw(sql);
if (prevBinaryOp && pt.operator !== prevBinaryOp) { if (prevBinaryOp && pt.operator !== prevBinaryOp) {
query.wrap('(', ')'); query.wrap('(', ')');

Loading…
Cancel
Save