views:

368

answers:

2

Hey guys,

I am converting an Access Jet-SQL query into T-SQL and I came upon the Int() function. Now, I would like to convert it into T-SQL, and this is what I have so far:

--Works for Positive
Select CONVERT(INT, 1.2)
--Answer = 1

--Not the same as Access
SELECT CONVERT(INT, -1.2)
--Answer = -1

Now, according to this, I need it to return -2, not -1. Does anyone have cleaner T-SQL code than:

DECLARE @test FLOAT
SET @test = -1.2

SELECT CASE WHEN @test < 0 THEN CONVERT(INT, @test) - 1 ELSE CONVERT(INT, @test) END

Can anyone come up with cleaner code than this (T-SQL only)? No UDFs as this is an adhoc query. Thanks!

+1  A: 

Oh yeah...

select convert(int, floor(@test))

Never mind...

Strommy
+3  A: 

SELECT FLOOR(@test)

Todd Owen