devxlogo

Arithmetic functions in SQL

Arithmetic functions in SQL

Question:
How do you create or access arithmetic functions like INT, MOD, or SQRT for use in Microsoft SQL Server?

Answer:
SQL Server supports math functions including SQRT, CEIL, FLOOR, and ROUND. As far as MOD goes, SQL Server supports the use of % instead of a MOD function. For example,

SELECT 3 % 2

results in 1.

When it comes to creating other functions that you can call from SQL Server, there are a couple of options:

  • You could create the function manually in a stored procedure using SQL.
  • You could create a DLL in VB or any other language that takes the two numbers and returns the remainder, and call it using the OLE automation stored procedures.
  • You could create an extended stored procedure in C++ and register it in SQL Server.

Hope this helps.

devx-admin

Share the Post: