日期:2014-05-17 浏览次数:20498 次
DECLARE @AA VARCHAR(20),@BB FLOAT
SELECT @AA = '3.42'
SELECT @BB = CONVERT(FLOAT,@AA)
SELECT
CASE WHEN CAST(@BB AS NUMERIC(10,2))-CAST(@BB AS INT) < 0.41 THEN CAST(@BB AS INT)
WHEN CAST(@BB AS NUMERIC(10,2))-CAST(@BB AS INT) > =0.41 AND CAST(@BB AS NUMERIC(10,2))-CAST(@BB AS INT)<0.91 THEN CAST(@BB AS INT)+0.5
WHEN CAST(@BB AS NUMERIC(10,2))-CAST(@BB AS INT) >= 0.91 THEN CAST(@BB AS INT)+1
END AS HH
--这样算简化吗?
DECLARE @AA VARCHAR(20),@BB FLOAT,@CC NUMERIC(10, 2)
SELECT @AA = '3.42',@BB = CAST(@AA AS FLOAT),@CC=CAST(@AA AS NUMERIC(10, 2)) - CAST(@BB AS INT)
SELECT
CASE
WHEN @CC< 0.41 THEN 0
WHEN @CC>= 0.91 THEN 1
ELSE 0.5
END +CAST(@BB AS INT) AS HH
DECLARE @AA VARCHAR(20),@BB FLOAT
SELECT @AA = '3.42'
SELECT @BB = CONVERT(FLOAT,@AA)
SELECT
CASE WHEN parsename(CAST(@BB AS varchar),1) < 41 THEN CAST(@BB AS INT)
WHEN parsename(CAST(@BB AS varchar),1) > =41 AND parsename(CAST(@BB AS varchar),1)<91 THEN CAST(@BB AS INT)+0.5
WHEN parsename(CAST(@BB AS varchar),1) >= 91 THEN CAST(@BB AS INT)+1
END AS HH
/*
HH
3.5
*/
SELECT CASE WHEN PARSENAME(@AA,1)<=41 THEN 0
WHEN PARSENAME(@AA,1)>91 THEN 1
ELSE 0.5
END
SELECT CAST(@AA*1.0 AS INT)+
CASE WHEN PARSENAME(@AA,1)<=41 THEN 0
WHEN PARSENAME(@AA,1)>91 THEN 1
ELSE 0.5
END