在TestDB数据库中,编写一个函数func_test_seq,要求:
1)参数
@N 整型
2)计算下式并作为函数的返回结果
1+22+32 +...+N2
测试语句:
select dbo.func_test_seq(1) r1, dbo.func_test_seq(15) r2,
dbo.func_test_seq(185) r3, dbo.func_test_seq(234) r4,
dbo.func_test_seq(469) r5
create function func_test_seq(@N int) returns int as begin declare @i int declare @sum int set @i = 1 set @sum = 0 while(@i<=@N) begin set @sum = @sum+@i*@i set @i = @i + 1 end return @sum end