--示例資料
create table tb(父物料 varchar(10),子物料 varchar(10))
insert tb select 'a1','b1'
union all select 'a1','b2'
union all select 'a1','b3'
union all select 'b1','c1'
union all select 'b1','c2'
union all select 'c1','d1'
union all select 'c1','d2'
go
--查詢自定義函式
create function f_cid(
@物料 varchar(10)
)returns @re table(物料 varchar(10),[level] int)
as
begin
declare @l int
set @l=0
insert @re select 子物料,@l from tb where 父物料=@物料
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.子物料,@l
from tb a,@re b
where a.父物料=b.物料 and b.[level]=@l-1
end
return
end
go
--查詢物料a1的物料
select * from f_cid('a1')
go
--刪除測試
drop table tb
drop function f_cid
/*--結果
物料 level
---------- -----------
b1 0
b2 0
b3 0
c1 1
c2 1
d1 2
d2 2
(所影響的行數為 7 行)
--*/
遞迴展開BOM
procedure wst agile bom extend p item id in number,p level in number iscursor cur p item in number is select id,item number,quantity,component from bo...
按BOM清單展開物料及需求(SQL)
適用環境 人工的去展開bom create function f pcode1 code varchar 20 returns re1 table code varchar 20 father varchar 20 uom varchar 5 quantity float,level1 int as...
BOM展開和反查函式
bom展開和反查函式cs15 css4 bom 展開 cs bom explosion mat bom explosion old version as of 3.0,use cs bom expl mat v2 cs bom expl mat v2 bom explosion for materi...