--未测试
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

解决方案 »

  1.   

    我是返回一个表,而且create function b(@a varchar(2))这个是先指定编号的阿我无法现在指定编号,编号是从循环a表取的,传给函数生成一个新表
      

  2.   

    函数 b(编号)是已经有的,是一个INT值
      

  3.   

    表c不存在用这个函数生成的
    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
      

  4.   

    for(int i=0;i<a.count,i++)
    {
      instert into tb (编号,money) values (a.编号,b(a.编号))
    }
    现实用SQL
    b(编号)返回一个INT