Anon246
Anon246

Reputation: 1841

ACCESS Jet SQL INT() Function -> SQL Server Function

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!

Upvotes: 2

Views: 2001

Answers (2)

Todd Owen
Todd Owen

Reputation: 16198

SELECT FLOOR(@test)

Upvotes: 3

Anon246
Anon246

Reputation: 1841

Oh yeah...

select convert(int, floor(@test))

Never mind...

Upvotes: 1

Related Questions