Browse Source

feat: WEEKDAY logic for mssql

pull/2706/head
Wing-Kam Wong 2 years ago
parent
commit
6064f9f201
  1. 18
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mssql.ts

18
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mssql.ts

@ -108,6 +108,24 @@ const mssql = {
END${colAlias}`
);
},
WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => {
// DATEPART(WEEKDAY, DATE): sunday = 1, monday = 2, ..., saturday = 7
// WEEKDAY() returns an index from 0 to 6 for Monday to Sunday
const m = {
monday: 0,
tuesday: 1,
wednesday: 2,
thursday: 3,
friday: 4,
saturday: 5,
sunday: 6,
};
return knex.raw(
`(DATEPART(WEEKDAY, ${fn(pt.arguments[0])}) - 2 - ${
m[pt?.arguments[1]?.value.toLowerCase()] || 0
} % 7 + 7) % 7 ${colAlias}`
);
},
};
export default mssql;

Loading…
Cancel
Save