日期:2014-05-18  浏览次数:20400 次

SQL编写计算(存储过程)
编写过程存储
现有表m,内有列a,b,c,d,e,f
欲编写存储过程并调用。实现对的公式a^2+b/c+d*e+(f+c^d)的计算。
如何为实现,尽量详细。

------解决方案--------------------
SQL code

go
if OBJECT_ID('test')is not null
drop table test
go
create table test(
a int,
b int,
c int,
d int,
e int,
f int
)

go
insert test
select 1,2,4,3,5,6 union all
select 2,3,1,6,5,7

--如果是处理表里的数据:
select a*a+c/b+d*e+f+c*c*c as value from test
/*
value
88
42
*/

go
if OBJECT_ID('pro_tracy')is not null
drop proc pro_tracy
go
create proc pro_tracy 
@a int,@b int,@c int,@d int,@e int,@f int
as
select @a*@a+@c/@b+@d*@e+@f+@c*@c*@c as total

exec pro_tracy 1,2,4,3,5,6
/*
total
88
*/

------解决方案--------------------
SQL code

select square(a) + b/c + d*e + (f + power(c, d))
from m;