算了,幫你改過來吧。
CREATE FUNCTION getbom (@bom0101 varchar(20))
RETURNS @tbom table(bom0401 varchar(20),bom0403 decimal(16,3))
AS
begin
declare @bom0401 varchar(20),@bom0403 decimal(16,3)
declare my_cursor cursor for
select bom0401,bom0403 from bom04 where bom0101=@bom0101
open my_cursor
fetch next from my_cursor into @bom0401,@bom0403
while @@fetch_status=0
begin
insert into @tbom select @bom0401,@bom0403
if exists(select *from bom04 where bom0101=@bom0401)
insert into @tbom select *from dbo.getbom(@bom0401)
fetch next from my_cursor into @bom0401,@bom0403
end
return
end