Connecting Tech Pros Worldwide Forums | Help | Site Map

UDF for a complex calculation

Newbie
 
Join Date: Jun 2007
Posts: 3
#1: Jun 18 '07
Hi,
The am a begginer in MS SQL.
The user defined function to calculate growt rate between two different quarters.
The input to the funtion is 2 columns.

CREATE FUNCTION Growth_Rate(@Qtr_Cur float, @Qtr_Pr float)
RETURNS float
AS
BEGIN
return (case when (sum(@Qtr_Pr)=0 and sum(@Qtr_Cur)<0) then (0)
when (sum(@Qtr_Pr)=0 and sum(@Qtr_Cur)>0) then (100)
when (sum(@Qtr_Pr)=0 and sum(@Qtr_Cur)=0) then (0)
else round((sum(@Qtr_Cur)/sum(@Qtr_Pr)-1)*100,1) end)


END

This gives a error msg : Only a scalar expression may be specified as the argument to the RETURN statement

Please help.

Reply