Foxtable(狐表)用户栏目专家坐堂 → BOM数据展开,制造业的高手请进!


  共有24090人关注过本帖树形打印复制链接

主题:BOM数据展开,制造业的高手请进!

帅哥哟,离线,有人找我吗?
唐尸三摆手
  21楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/4/18 11:09:00 [只看该作者]

多级反展和用途反展(顶层反展)的代码执行速度好艰难啊,大约2分钟,太慢了,另外这两个功能的代码为什么会报错呢,代码如下:
dim al as string=Forms("frm_b").Controls("TextBox1").value
'多级反展:
 Dim s As String =  " ;with cte As "  & _
    "(select * from abt00000 where childitem = '"  & al  & "'  "  & _
    "union all  "  & _
    "select a.* from abt00000 a  "  & _
    "join cte on a.childitem  = cte.parentitem) "  & _
    "select  * from cte "
    tables("frm_b_table1").Fill(s,"erp",true)

'用途反展:
Dim s As String =  " ;with cte As "  & _
    "(select * from abt00000 where childitem = '"  & al  & "'  "  & _
    "union all  "  & _
    "select a.* from abt00000 a  "  & _
    "join cte on a.childitem  = cte.parentitem) "  & _
    "select  * from cte left join abt00000 b on cte.parentitem = b.childitem where b.childitem is null"
    tables("frm_b_table1").Fill(s,"erp",true)



图片点击可在新窗口打开查看此主题相关图片如下:pic089.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2010-4-18 11:09:13编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lxl
  22楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:858 积分:6071 威望:0 精华:19 注册:2008/9/1 9:13:00
  发帖心情 Post By:2010/4/18 13:12:00 [只看该作者]

正展不慢,反展慢?
你看看parentitem是不是没加索引?


语法错误可以 output.show(s)。然后把结果放到企业管理器里面检查


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  23楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/4/18 15:31:00 [只看该作者]

这样测试了一下:

dim al as string="B-WG-XJ-DG-53"
'多级反展
 Dim s As String =  " ;with cte As "  & _
    "(select * from abt00000 where childitem = '"  & al  & "'  "  & _
    "union all  "  & _
    "select a.* from abt00000 a  "  & _
    "join cte on a.childitem  = cte.parentitem) "  & _
    "select  * from cte "

output.show(s)

显示结果为:
 ;with cte As (select * from abt00000 where childitem = 'B-WG-XJ-DG-53'  union all  select a.* from abt00000 a  join cte on a.childitem  = cte.parentitem) select  * from cte
然后拷入查询管理器中:执行到2分30秒还没显示结果


可是为什么正展在瞬间就显示结果呢? 

 

 

 

[此贴子已经被作者于2010-4-18 15:34:27编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lxl
  24楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:858 积分:6071 威望:0 精华:19 注册:2008/9/1 9:13:00
  发帖心情 Post By:2010/4/18 21:17:00 [只看该作者]

以下是引用唐尸三摆手在2010-4-18 15:31:00的发言:

这样测试了一下:

dim al as string="B-WG-XJ-DG-53"
'多级反展
 Dim s As String =  " ;with cte As "  & _
    "(select * from abt00000 where childitem = '"  & al  & "'  "  & _
    "union all  "  & _
    "select a.* from abt00000 a  "  & _
    "join cte on a.childitem  = cte.parentitem) "  & _
    "select  * from cte "

output.show(s)

显示结果为:
 ;with cte As (select * from abt00000 where childitem = 'B-WG-XJ-DG-53'  union all  select a.* from abt00000 a  join cte on a.childitem  = cte.parentitem) select  * from cte
然后拷入查询管理器中:执行到2分30秒还没显示结果


可是为什么正展在瞬间就显示结果呢? 

 

 

 

[此贴子已经被作者于2010-4-18 15:34:27编辑过]


应该索引的原因。parentitem列没有加索引。
可以把abt00000  只留部分实例数据 然后备个份发给我。看到结构才能分析原因。


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  25楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/4/19 8:18:00 [只看该作者]

好的,文件太大了,邮箱是多少,发邮件吧

[此贴子已经被作者于2010-4-19 8:20:47编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lxl
  26楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:858 积分:6071 威望:0 精华:19 注册:2008/9/1 9:13:00
  发帖心情 Post By:2010/4/19 9:20:00 [只看该作者]

jiabiao@yeah.net

 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  27楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/4/20 8:18:00 [只看该作者]

不知道版主有没有进展,想提个问题,既然BOM多级正展可以这样实现:
;with cte As
(
select * from BOM表 where parentitem = '产品编码'
union all
select a.* from BOM表 a
join cte on a.parentitem  = cte.childitem
)
select  * from cte

那是不是就可以计算出某时间段内所有订单的各级物料需求:

;with cte As
(
select * from BOM表 where parentitem  in (select distinct itemcode from 订单表 where requiredate between '2010-05-05' and '2010-05-10')
union all
select a.* from BOM表 a
join cte on a.parentitem  = cte.childitem
)
select  * from cte

不知道这样分析对不对,版主请指教
[此贴子已经被作者于2010-4-20 8:19:31编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lxl
  28楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:858 积分:6071 威望:0 精华:19 注册:2008/9/1 9:13:00
  发帖心情 Post By:2010/4/20 9:24:00 [只看该作者]

以下是引用唐尸三摆手在2010-4-20 8:18:00的发言:
不知道版主有没有进展,想提个问题,既然BOM多级正展可以这样实现:
;with cte As
(
select * from BOM表 where parentitem = '产品编码'
union all
select a.* from BOM表 a
join cte on a.parentitem  = cte.childitem
)
select  * from cte

那是不是就可以计算出某时间段内所有订单的各级物料需求:

;with cte As
(
select * from BOM表 where parentitem  in (select distinct itemcode from 订单表 where requiredate between '2010-05-05' and '2010-05-10')
union all
select a.* from BOM表 a
join cte on a.parentitem  = cte.childitem
)
select  * from cte

不知道这样分析对不对,版主请指教
[此贴子已经被作者于2010-4-20 8:19:31编辑过]

恩,对的。

那个结构问题明天看吧
这两天上面交代了一个限期任务,明天才能搞定图片点击可在新窗口打开查看


 回到顶部
帅哥哟,离线,有人找我吗?
唐尸三摆手
  29楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:928 积分:7769 威望:0 精华:13 注册:2008/9/1 11:58:00
  发帖心情 Post By:2010/4/21 11:18:00 [只看该作者]

版主,既然根据多级正展能够计算出订单的物料需求,那么如何设置才能得到正确的结果呢?

序号 母件编码 子件编码 耗料数量
5 CP-WG-JSG-0210                           B-WG-DGG-09                              12
492 B-WG-DGG-09                              YCL-WXJ-CYJ-0040                         1


上面的数据关系应该保证YCL-WXJ-CYJ-0040的耗料数量也要12个才对呀

 回到顶部
帅哥哟,离线,有人找我吗?
lxl
  30楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:858 积分:6071 威望:0 精华:19 注册:2008/9/1 9:13:00
  发帖心情 Post By:2010/4/21 16:09:00 [只看该作者]

反展慢的确是索引的原因。我用你的数据测试过,加了索引,反展也是瞬间完成。
你看看你有没权限执行下面代码:
CREATE NONCLUSTERED INDEX [b] ON [dbo].[abt0000]
(
 [childitem] ASC
)

如果没有权限,唯一的办法是让你们的系统管理员,或者软件开发商给childitem列加上索引了。


29楼如果需要子件的耗料数量一直累积相乘,这样改一下代码即可:
;with cte As
(
select *,cast(1 as numeric(18,4)) As CalcNum from abt0000 where parentitem = 'CP-WG-JSG-0210                          '
union all
select a.*,cast(a.num * cte.CalcNum as numeric(18,4)) from abt0000 a
join cte on a.parentitem  = cte.childitem
)
select  * from cte



[此贴子已经被作者于2010-4-21 16:10:04编辑过]

 回到顶部
总数 40 上一页 1 2 3 4 下一页