pape pape - 5 months ago 25
SQL Question

SQL - division two float number

I have numbers (from my select)

col1 col2
1. 3.6 and 3
2. 3.6 and 5


I want this

if(col1/col2 = integer)
update column
else(col1/col2 = decimal number)
update column


Any idea how to get is number integer or decimal?

Answer

You could use modulo 1 (% 1), and if the remainder is zero then you have your 'integer'. For example, with SQL Server:

if (col1 / col2 ) % 1 = 0 
   -- integer
else
   -- decimal
Comments