pape
pape

Reputation: 239

SQL - test if numeric field is holding an integer

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?

Upvotes: 0

Views: 531

Answers (1)

Paul Ellery
Paul Ellery

Reputation: 1745

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

Upvotes: 2

Related Questions