Average a column without using aggregate function in sql server

Hi Prabhu,

I tried to calculate average using Cursor

DECLARE @T TABLE( Marks INT)
Insert into @T values ( 12),(13),(15),(85);

DECLARE @Marks int
Declare @sum int
Declare @i int

Set @sum= 0
Set @i=0

DECLARE MYCURSOR CURSOR FOR
Select * from @T

open Mycursor
fetch next from MYCURSOR into @Marks

while (@@FETCH_STATUS=0)
Begin
Set @sum = @sum+@Marks
Set @i=@i+1
fetch next from MYCURSOR into @Marks
end
Print @sum
Print @sum/@i

Close Mycursor
Deallocate mycursor

Regards
Anna