Coder2599 Coder2599 - 6 months ago 34
SQL Question

How to determine whether the number is float or integer in SQL Server?

I need to write this query in sql server:

IF isFloat(@value) = 1
BEGIN
PRINT 'this is float number'
END
ELSE
BEGIN
PRINT 'this is integer number'
END


Please help me out with this, thanks.

Answer
declare @value float = 1

IF FLOOR(@value) <> CEILING(@value)
BEGIN
    PRINT 'this is float number'
END
ELSE
BEGIN
    PRINT 'this is integer number'
END