ACCESS Jet SQL INT () & # 8594; SQL Server function

I am converting an Access Jet-SQL query to T-SQL and I came across the Int () function. Now I would like to convert it to 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 and 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 think of a cleaner code than this (T-SQL only)? No UDF as this is an adhoc request. Thank!

+2


source to share


2 answers


SELECT FLOOR (@test)



+3


source


Oh yeah...

select convert(int, floor(@test))

      



Nothing...

+1


source







All Articles