SQL equivalent of Math.Floor() in c#
I just want to convert 10.111
to 10 based on some condition in the following Query
Select
case when 2=1 then
CONVERT(de开发者_开发知识库cimal(10,3), 10.111)
else
CONVERT(decimal(10,0), 10.111)
end
But it return 10.000 How can i get 10?
The CASE
expression as a whole must all evaluate to the same datatype. The only way of having one branch evaluate to decimal(10,3)
and the other to a different datatype would be to do a cast to sql_variant
Select
case when 2=1 then
CONVERT(decimal(10,3), 10.111)
else
CAST(FLOOR( 10.111) AS SQL_VARIANT)
end
精彩评论