Advertisement
Advertisement
| 07.15.2008 at 08:14PM PDT, ID: 23568412 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: |
ALTER FUNCTION [dbo].[fn_GetMonthColorIndicator] (@MonthProgress int, @MonthTarget int) RETURNS SQL_VARIANT AS BEGIN DECLARE @MonthColorIndicator SQL_VARIANT, @MonthProgressPercent SQL_VARIANT SET @MonthProgressPercent = ( CASE WHEN @MonthProgress = 0 OR @MonthTarget = 0 THEN 0 ELSE (CAST(@MonthProgress AS FLOAT)/CAST(@MonthTarget AS FLOAT)*100) END ) SET @MonthColorIndicator = ( CASE WHEN @MonthProgressPercent >='85' THEN 'Green' WHEN @MonthProgressPercent >='60' THEN 'Yellow' WHEN @MonthProgressPercent >'0' THEN 'Red' ELSE 'Green' --if zero, then also green (target is zero) END ) RETURN (SELECT @MonthColorIndicator) --gives same indicator for all rows!!! --RETURN (SELECT @MonthProgressPercent) --will return correct calculation for each insert/update call to this function. END |