--未测试
create function b(@a varchar(2))
returns int
as beging
declare @i int
set @i=0
select @i=count(*) from a where 编号=@a
return @i
end
godelclare @a varchar(2)
set @a=''
while @a is not null
begin
select @a=min(编号) from a where 编号>@a
if @a is not null
begin
insert c select @a,dbo.b(@a)
end
end
go
create function b(@a varchar(2))
returns int
as beging
declare @i int
set @i=0
select @i=count(*) from a where 编号=@a
return @i
end
godelclare @a varchar(2)
set @a=''
while @a is not null
begin
select @a=min(编号) from a where 编号>@a
if @a is not null
begin
insert c select @a,dbo.b(@a)
end
end
go
f_销售_金额(日期,编号)这个是一个返回金额表的函数
不知道为什么我下边的函数总是报错CREATE function f_弃用()
returns @tb table(编号 varchar(100) ,money int)
as
begin
declare @a varchar(2)
declare @i int
declare @inumber intset @a=''
set @i=0
set @inumber=(select count(*)from PF_销售单)while(@i<@inumber)
begin
set @i=@i+1
select @a=min(编号) from a where 编号>@a
insert into @tb
select @a,sum(金额) from f_销售_金额('2006-05-25','@a')
endreturn
end
{
instert into tb (编号,money) values (a.编号,b(a.编号))
}
现实用SQL
b(编号)返回一个INT