我创建了以下存储过程来计算百分比,它工作正常,但我总是无法得到确切的结果
例如98.000
,而不是98.947
CREATE PROCEDURE sp_finger_calc_percent
AS
DECLARE @no_action decimal(18,4);
DECLARE @yes_action decimal(18,4);
SELECT @no_action = COUNT(*)
FROM Action INNER JOIN
Employee ON Action.b_num = Employee.b_num INNER JOIN
Department ON Employee.dep_id = Department.dep_id
WHERE (Department.dep_id = 50) AND (Action.action = 0);
SELECT @yes_action= COUNT(*)
FROM Action INNER JOIN
Employee ON Action.b_num = Employee.b_num INNER JOIN
Department ON Employee.dep_id = Department.dep_id
WHERE (Department.dep_id = 50) AND (Action.action = 1);
If(@no_action = 0.00)
return 100.00
Else return cast( (100.00 *(@yes_action /@no_action ) )as decimal(18,4))
;
DECLARE @return_status decimal(18,4);
EXEC @return_status = sp_finger_calc_percent
select @return_status;