2016-06-28 57 views
0

我有一個數字(從我的選擇)SQL - 測試如果數字字段值爲整數

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

我想這

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

不知道如何得到的是數字的整數或小數點?

+0

如果你的COL1總是漂浮/十進制/實,然後你用INT輸出劃分它,除非你施放 – TheGameiswar

+0

,你可以用它來檢查,如果小數點絕不會是一個INT值足夠接近整數:'a.col1/a.col2 = round(a.col1/a.col2,0)然後'integer'else'decimal'end'時的情況 - 至少在MySQL中 –

+0

標記dbms用過的。有些產品在這裏表現不同。 – jarlh

回答

2

你可以使用模1(%1),如果餘數爲零,那麼你有你的'整數'。例如,與SQL Server:

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

非常感謝,就是這樣 – pape

相關問題