Using math functions in Sql with MS Access

simplfuzz picture simplfuzz · Aug 7, 2009 · Viewed 14.8k times · Source

I designed a query in SQL View using MS Access:

select floor(num1) from t1;

When I run it, I get "undefined function floor".

I get similar errors for Ceil, Mod,Power, Sign, Sqrt, Trunc, and initcap functions.

Does the Access database engine's SQL syntax have equivalent functions?

Answer

David-W-Fenton picture David-W-Fenton · Aug 8, 2009

Replace Floor() with Int(). I learned this by searching in the Access help files, in this case, hitting F1 while in the query designer, and searching for "functions." That took me to a help topic comparing VBA and T-SQL functions.

You should probably have a look at the Access database engine SQL Reference. I can't find a good online reference for functions that are supported through the Jet/ACE and Access expression services. For some unknown reason, the Access Help has not included Jet/ACE expressions since Jet 3.0 and this aged resource was finally removed from MSDN a year or two ago :(

Keep in mind that the Jet/ACE expression service for use outside Access supports a much smaller subset of functions that is possible using the Access Expression Service when running your SQL inside Access 2007. Broadly speaking, the VBA5 functions (as distinct from methods) that involve simple data types (as distinct from, say, arrays or objects) are supported outside of the Access user interface; for an approximate list of function names see the 'Use Sandbox mode operations with Jet 4.0 Service Pack 3 and later' section of this MSDN article.

Also, the functions reference in the VBE help should be a starting place.

The help files are not perfect, but a little searching ought to get you what you need.