会员名称: 登录密码: (找回密码) 登录 会员注册

分类

问题
上个主题 下个主题
主题:继续在线寻SQL取数据方法。取销售订单中所使用的明细物料
avatar
daniel439
IT 行业
Ta擅长:
本周回答(0),本月回答(0)
发贴时间:2007-11-9 14:10:44   完成时间: 2007-11-16 8:24:02
赠分:20      回答:10   已经到期    
如果找出07年销售订单产品中用到变压器的物料?
我不明白的是,销售订单中的明细是不是就是物料?也有可能是成品,那要找到哪些成品用到变压器?还需要用到哪些表?
大侠们用SQL语句给指点一下吧。。
修改时间:2007-11-9 14:56:00

没人知道呀?
我现在要得到07年销售订单中,哪些订单产品用到变压器这个物料,所用到变压器的总金额。引出的表必须包含销售订单号、销售产品内码、销售产品代码、订单数量、出库数量、所用到变压器的内码、料号、名称、规格、供应商、价格、用量、金额,如果变压器有几个供应商同时供应,体现价格信息最后生效的那家供应商。

谁能给出答案?


补充时间:2007-11-9 17:07:24
avatar
victor596
IT 行业
Ta擅长:
SOA(1),K/3 BOS其他(1) 本周回答(0),本月回答(0)
回答时间:2007-11-12 9:08:45
Step 1.確定用到此物料的 所有父級 半成品/產成品.用fmProc_Bom_GetPItem過程可以取到數
go
if exists (select 1 from sysobjects where name='fmProc_Bom_DoItem')drop procedure fmProc_Bom_DoItem
go
if exists(select 1 from sysobjects where name='fmProc_Bom_GetPItem')drop procedure fmProc_Bom_GetPItem
/*
功能:抓取所有用到此產品內碼的父產品內碼
作者:Victor
日期:2007-8-25
*/
go
create procedure fmProc_Bom_DoPItem
(
@fitemid int
)
as
set nocount on
declare @pitem int
declare pm_cur cursor local for
select b.fitemid from icbom b inner join (select * from icbomchild where fitemid=@fitemid and FMaterielType=371) a
on a.finterid=b.finterid inner join t_icitem c on b.fitemid=c.fitemid where b. fusestatus=1072 and b.fbomtype=0 and b.fcancellation=0
and c.ferpclsid=2
open pm_cur
fetch pm_cur into @pitem
if @@cursor_rows=0
begin
close pm_cur
deallocate pm_cur
return
end
while @@fetch_status=0
begin
insert into #temp(fitemid) values(@pitem)
exec fmProc_Bom_DoPItem @pitem
fetch next from pm_cur into @pitem
end
close pm_cur
deallocate pm_cur
go
create procedure fmProc_Bom_GetPItem --取此類物料的所有父物料
(
@fitem int
)
as
set nocount on
create table #temp(fitemid int)
exec fmProc_Bom_DoPItem @fitem
select * from #temp
drop table #temp
go

Step 2. 根據取到的產成品/半成品 內碼 取得相應的銷售訂單。這就應該有簡單了

提示:fmProc_Bom_GetPItem 取到的產成品/半成品 是內碼
以上希望可以幫上你。
发文者评价: (共获积分:20
 
网友评价: 100%       0%     (目前有 3 人评价)
你的评价:
其他回答
avatar
daniel439
IT 行业
Ta擅长:
本周回答(0),本月回答(0)
回答时间:2007-11-9 23:51:29
这个没人知道了呀??是不是没人愿意回答呢?
 
avatar
浣花
IT 行业
Ta擅长:
本周回答(0),本月回答(0)
回答时间:2007-11-10 9:22:44
这个取数关联太复杂了吧,如果你要筛条件,就到组装件BOM单的表里筛吧。
四叠阳关 唱到千千遍……
 
avatar
daniel439
IT 行业
Ta擅长:
本周回答(0),本月回答(0)
回答时间:2007-11-10 13:21:47
还有人知道不啊?
 
avatar
灵魂大师
IT 行业
Ta擅长:
K/3 BOS(29),SOA(18) 本周回答(0),本月回答(0)
回答时间:2007-11-11 20:36:59
很想帮你,但涉及到BOM表,这个没做过
 
avatar
剑南春之歌
IT 行业
Ta擅长:
金蝶K/3(14),K/3其他(5) 本周回答(0),本月回答(0)
回答时间:2007-11-11 22:29:56
第一个问题是物料批次跟踪表
第二个问题采购供应商物料对应表

http://blog.vsharing.com/zhanghb/
厚德载物,宁静致远.
 
avatar
victor596
IT 行业
Ta擅长:
SOA(1),K/3 BOS其他(1) 本周回答(0),本月回答(0)
回答时间:2007-11-12 9:28:37
以下是我目前有關BOM中的所有SQL,你可能需要再修改一下,因為計算BOM需要較長的時間,所以有些過程寫進了自己新建的TABLE.
go
if exists (select 1 from sysobjects where name='fmProc_Bom_DoPItem')drop procedure fmProc_Bom_DoPItem
go
if exists(select 1 from sysobjects where name='fmProc_Bom_GetPItem')drop procedure fmProc_Bom_GetPItem
/*
功能:抓取所有用到此產品內碼的父產品內碼
作者:Victor
日期:2007-8-25
*/
go
create procedure fmProc_Bom_DoPItem
(
@fitemid int
)
as
set nocount on
declare @pitem int
declare pm_cur cursor local for
--取得用此產品編號的父產品 可以修改條件來篩選想要的記錄
select b.fitemid from icbom b inner join (select * from icbomchild where fitemid=@fitemid and FMaterielType=371) a
on a.finterid=b.finterid inner join t_icitem c on b.fitemid=c.fitemid where b. fusestatus=1072 and b.fbomtype=0 and b.fcancellation=0
and c.ferpclsid=2
open pm_cur
fetch pm_cur into @pitem
if @@cursor_rows=0
begin
close pm_cur
deallocate pm_cur
return
end
while @@fetch_status=0
begin
insert into #temp(fitemid) values(@pitem)
exec fmProc_Bom_DoPItem @pitem
fetch next from pm_cur into @pitem
end
close pm_cur
deallocate pm_cur
go
create procedure fmProc_Bom_GetPItem --取此類物料的所有父物料 fmProc_Bom_GetPItem 2606
(
@fitem int
)
as
set nocount on
create table #temp(fitemid int)
exec fmProc_Bom_DoPItem @fitem
select * from #temp
drop table #temp
go
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fmFun_Base_UnitTrans') DROP function fmFun_Base_UnitTrans
/*
功能:單位數據轉換
作者:Victor
日期:2007-8-25
*/
GO
create function fmFun_Base_UnitTrans(@unit1 as int,@unit2 as int)
--單位轉換 1@unit1=?@unit2
returns decimal(12,5)
begin
if (select count(distinct funitgroupid) from t_measureunit where fmeasureunitid in (@unit1,@unit2))=2 return -1
declare @g int,@du int
select @g=funitgroupid from t_measureunit where fmeasureunitid=@unit1
select @du=fdefaultunitid from t_unitgroup where funitgroupid=@g
declare @ret decimal(12,5)
declare @u1d decimal(12,5),@u2d decimal(12,5)
select @u1d=fcoefficient from t_measureunit where fmeasureunitid=@unit1
select @u2d=fcoefficient from t_measureunit where fmeasureunitid=@unit2
if @du=@u1d
set @ret=@u2d/@u1d
else
set @ret=@u1d/@u2d
return @ret
end
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fmProc_Bom_Cal') DROP procedure fmProc_Bom_Cal
GO
/*-- =============================================
功能: 累加性的BOM計算,不能單獨調用,只能在 fmProc_Bom_CalQty中調用
參數:
返回:數據集
作者:Victor
日期:2007-08-23
最後作者:
最後日期:
范例:
-- =============================================*/
create procedure fmProc_Bom_Cal --累加性的BOM計算
(
@pid int, @cc bit, @qtymond decimal(12,5) ,@level int,@unitid int
)
as
set nocount on
declare @curlevel int
set @curlevel=@level+1
declare @bomid int,@sonpid int,@scrap decimal(12,5),@qty int,@sonqty decimal(12,5),@unit int,@punit int,@sqty decimal(12,5)
if not exists(select 1 from icbom where fitemid=@pid and fusestatus=1072 and fbomtype=0 and fcancellation=0)return
select @bomid=finterid,@qty=fqty,@punit=funitid from icbom where fitemid=@pid and fusestatus=1072 and fbomtype=0 and fcancellation=0
if @level=0 insert into #retv(curLevel,BomId,ParentPid,SonPid,UnitId,Fqty,FPqty,Fsqty)values(0,@bomid,@pid,@pid,@punit,1,@qty,@qty)
set @qtymond=@qtymond* dbo.fmfun_base_unittrans(@punit,@unitid) --轉換單位
declare pm_cur cursor local for select fitemid,fauxqty/@qty*@qtymond,fscrap,funitid,fauxqty from icbomchild where finterid=@bomid and FMaterielType=371
open pm_cur
fetch pm_cur into @sonpid,@sonqty,@scrap,@unit,@sqty
while @@fetch_status=0
begin
if @cc=1 set @sonqty=@sonqty*(1+@scrap/100)
insert into #retv(curLevel,BomId,ParentPid,SonPid,UnitId,Fqty,FPqty,Fsqty) values(@curlevel,@bomid,@pid,@sonpid,@unit,@sonqty,@qty,@sqty)
exec fmProc_Bom_Cal @sonPid,@cc,@sonqty,@curlevel,@unit
fetch next from pm_cur into @sonpid,@sonqty,@scrap,@unit,@sqty
end
close pm_cur
deallocate pm_cur
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fmProc_Bom_CalQty') DROP procedure fmProc_Bom_CalQty
GO
/*-- =============================================
功能: 計算子物料在成品物料中的總用量
參數:
返回:數據集
作者:Victor
日期:2007-08-23
最後作者:
最後日期:
范例: fmProc_Bom_CalQty 1,15484,0
-- =============================================*/
create procedure fmProc_Bom_CalQty
(
@sonitem int, --子物料
@parentitem int, --成品物料
@considescrap bit --是否考慮損耗
)
as
declare @level int,@unitid int
set nocount on
set @level=0
-- if not exists(select * from tempdb.dbo.sysobjects where name='#retv')
-- begin
create table #retv
(
curLevel int , --BOM層次級
BomId int, --BOM內碼
ParentPid int , --父物料內碼
SonPid int , --子物料內碼
UnitId int, --單位
Fqty decimal(12,5) , --數量
FPQty decimal(12,5), --BOM中父物料的數量,設計數量
FSQty decimal(12,5) --標准數量
)
-- end
select @unitid=funitid from t_icitem where fitemid=@parentitem
exec fmProc_Bom_Cal @parentitem,@considescrap,1,@level,@unitid
if @sonitem =-1
select * from #retv
else
select * from #retv where sonpid=@sonitem
drop table #retv
go
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fmProc_Bom_GetQtyAll') DROP procedure fmProc_Bom_GetQtyAll
GO
/*-- =============================================
功能: 計算子物料在成品物料中的總用量
參數:
返回:數據集
作者:Victor
日期:2007-08-23
最後作者:
最後日期:
范例: fmProc_Bom_GetQtyAll '','5.0.0.LDPE.160AT+RTS4968(100)'
*/
create procedure fmProc_Bom_GetQtyAll
(
@pid1 varchar(80),
@pid2 varchar(80),
@cc bit=0
)
as
declare @sonitem int,@parentitem int
set nocount on
select @sonitem=fitemid from t_icitem where fnumber=@pid1
if @sonitem is null set @sonitem=-1
select @parentitem=fitemid from t_icitem where fnumber=@pid2
create table #tmp
(
curLevel int ,
BomId int,
ParentPid int,
SonPid int,
UnitId int,
Fqty decimal(12,5),
fpqty decimal(12,5),
fsqty decimal(12,5)
)
if @parentitem is not null
insert into #tmp exec fmProc_Bom_CalQty @sonitem,@parentitem,@cc
-- insert into #tmp exec fmProc_Bom_CalQty -1,@parentitem,0
-- select * from #tmp
create table #tmpv
(
FItemId int,
FUnitId int,
FQty decimal(12,5)
)
if @sonitem =-1
insert into #tmpv select SonPid,UnitId,Fqty from #tmp
else
insert into #tmpv select sonPid,UnitId,Fqty from #tmp where SonPid=@sonitem
-- select * from #tmpv
drop table #tmp
update a set a.funitid=b.funitid,a.fqty=a.fqty* dbo.fmfun_base_unittrans(a.funitid,b.funitid) from #tmpv a
inner join t_icitem b on a.fitemid=b.fitemid
select b.fnumber,b.fname,b.fmodel,c.fname,a.total from ( select fitemid,funitid, sum(fqty) as total from #tmpv group by fitemid,funitid )a
inner join t_icitem b on a.fitemid=b.fitemid inner join t_measureunit c on a.funitid=c.fmeasureunitid where b.fnumber<>@pid2 order by b.fnumber
drop table #tmpv
go
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fmProc_Bom_GetItemQty') DROP procedure fmProc_Bom_GetItemQty
GO
/*-- =============================================
功能: 計算子物料在成品物料中的總用量 按產品內碼 只適於1對1的情形
參數:
返回:數據集
作者:Victor
日期:2007-08-23
最後作者:
最後日期:
范例: fmProc_Bom_GetItemQty @sonpid,@ppid,0
*/
create procedure fmProc_Bom_GetItemQty
(
@sonitem int,
@parentitem int,
@cc bit=0
)
as
set nocount on
create table #tmp
(
curLevel int ,
BomId int,
ParentPid int,
SonPid int,
UnitId int,
Fqty decimal(12,5),
fpqty decimal(12,5),
fsqty decimal(12,5)
)
if @parentitem is not null
insert into #tmp exec fmProc_Bom_CalQty @sonitem,@parentitem,@cc
-- insert into #tmp exec fmProc_Bom_CalQty -1,@parentitem,0
-- select * from #tmp
create table #tmpv
(
FItemId int,
FUnitId int,
FQty decimal(12,5),
FPItemId int
)
insert into #tmpv(FItemId,FUnitId,Fqty,FPItemId) select SonPid,UnitId,Fqty,ParentPid from #tmp
-- select * from #tmpv
drop table #tmp
update a set a.funitid=b.funitid,a.fqty=a.fqty* dbo.fmfun_base_unittrans(a.funitid,b.funitid) from #tmpv a
inner join t_icitem b on a.fitemid=b.fitemid
/*
insert into fmtempdb0824(fnumber,fname,fmodel,funit,fqty,fparent) --插入一張物料表中在別處定義的
select b.fnumber,b.fname,b.fmodel,c.fname,a.total,d.fnumber from
( select fitemid,funitid, FPItemId,sum(fqty) as total from #tmpv group by fitemid,funitid,FPItemId )a
inner join t_icitem b on a.fitemid=b.fitemid inner join t_measureunit c on a.funitid=c.fmeasureunitid
inner join t_Icitem d on a.FPItemId=d.fitemid
where b.fitemid<>@parentitem order by b.fnumber
*/
insert into fmtempdb0824(fsonpid,fparentpid,funitid,fqty)
select fitemid, FPItemId,funitid,sum(fqty) from #tmpv where fitemid<>fpitemid group by fitemid,funitid,FPItemId
drop table #tmpv
return 1
go
 
avatar
victor596
IT 行业
Ta擅长:
SOA(1),K/3 BOS其他(1) 本周回答(0),本月回答(0)
回答时间:2007-11-12 10:51:31
你那個問題,其實不必要去 抓取BOM表,我認為 可以這樣子:
1. 去抓取有 此變壓器的 投料單 (PPBOMEntry表)
2. 找投料單PPBOMENTRY 中 生產任務單(字段 Ficmointerid)
3. 根據生產任務單內碼,去抓取銷售訂單號 (ICMO表,FOrderInterId字段指出了銷售訂單號)
4. 根據銷售訂單號 去 找銷售訂單 (Seorder ,SeorderEntry)

供應商的供貨資料在 t_Supply,t_SupplyEntry中
View as RSS news feed in XML
© 2008 金蝶国际软件集团 版权所有  Version:3.2.2008.27643 页面时间:179.2404Ms