create function get_sum(@id int) returns int as declare @sum int select @sum = sum(a.c)+sum(b.d+b.e) from a,b where a.id = b.id and a.id = @id return @sum end go
create function dbo.f_test (@id int) returns table as return select a.c+b.d+b.e from a,b where a.id=b.id and ID=@id
create view sumtable as select a.ID, isnull(a.C,0)+isnull(b.D,0)+isnull(b.E,0) as sums from a left join b on a.ID=b.ID go
declare @id int
set @id = ???select sum(a.c)+sum(b.d+b.e)
from a,b
where a.id = b.id and a.id = @id--怎么还用函数呢?
update a set a=b.D+b.E from a left join b on a.ID=b.ID
create function get_sum(@id int)
returns int
as
declare @sum int
select @sum = sum(a.c)+sum(b.d+b.e)
from a,b
where a.id = b.id and a.id = @id
return @sum
end
go
returns table
as
return
select a.c+b.d+b.e from a,b
where a.id=b.id
and ID=@id
as
select a.ID, isnull(a.C,0)+isnull(b.D,0)+isnull(b.E,0) as sums
from a left join b on a.ID=b.ID
go