drop table #tmp1999
drop table #tmp2999
drop table #tmp3999
drop table #tmp4999
drop table #tmp5999
drop table #tmp6999
drop table #tmp7999
drop table #tmp8999
drop table #tmp9999
drop table #tmp1 create table #tmp1999
(
[autoid] [int] IDENTITY(1,1) NOT NULL,
[opcomponentid] [nvarchar](100) NULL,
[bomid] [nvarchar](100) NULL,
[sortseq] [nvarchar](20) NULL,
[componentid] [nvarchar](100) NULL,
[baseqtyn] [decimal](10, 4) NULL,
[baseQtyD] [decimal](10, 4) NULL ) delete #tmp1999 declare @id int
set @id=(select min(autoid) from SO_SODetails /*where cInvCode='1C00601009'*/ )
---声明一个变量,销售明细里面最小的ID号赋值给变量
while(@id)<=(select max(autoid) from SO_SODetails /*where cInvCode='1C00601009'*/)
---当@id<=销售订单明细表最大ID时,循环
begin
insert into #tmp1999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select iQuantity from SO_SODetails where autoid=@id )) as baseqitn,
baseQtyD from bom_opcomponent
----查询BOM子表并插入到#Tmp1999中
where BomId =(
select MAX( BomId) as bomid from bom_parent where ParentId = (
select partid from bas_part
where InvCode = (
select cinvcode from SO_SODetails
where AutoID=@id)))) set @id=@id+1
end ----根据#tmp1999创建一个数据结构相同的表 #tmp2999
select * into #tmp2999 from #tmp1999 where 1=0 /***
第二次循环,查找tmp#1999中的子件
***/
delete #tmp2999
set @id=(select min(autoid)from #tmp1999)
while @id<=(select max(autoid)from #tmp1999 )
begin
insert into #tmp2999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp1999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp2999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp1999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp3999 from #tmp1999 where 1=0
/***
第三次循环,查找tmp#2999中的子件
***/
delete #tmp3999
set @id=(select min(autoid)from #tmp2999)
while @id<=(select max(autoid)from #tmp2999 )
begin
insert into #tmp3999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp2999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp3999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp2999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp4999 from #tmp1999 where 1=0
/***
第四次循环,查找tmp#3999中的子件
***/
delete #tmp4999
set @id=(select min(autoid)from #tmp3999)
while @id<=(select max(autoid)from #tmp3999 )
begin
insert into #tmp4999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp3999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp4999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp3999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp5999 from #tmp1999 where 1=0
/***
第四次循环,查找tmp#4999中的子件
***/
delete #tmp5999
set @id=(select min(autoid)from #tmp4999)
while @id<=(select max(autoid)from #tmp4999 )
begin
insert into #tmp5999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp4999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp5999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp4999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp6999 from #tmp1999 where 1=0
/***
第六次循环,查找tmp#5999中的子件
***/
delete #tmp6999
set @id=(select min(autoid)from #tmp5999)
while @id<=(select max(autoid)from #tmp5999 )
begin
insert into #tmp6999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp5999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp5999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp5999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp7999 from #tmp1999 where 1=0
/***
第七次循环,查找tmp#6999中的子件
***/
delete #tmp7999
set @id=(select min(autoid)from #tmp6999)
while @id<=(select max(autoid)from #tmp6999 )
begin
insert into #tmp7999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp6999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp7999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp6999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp8999 from #tmp1999 where 1=0
/***
第八次循环,查找tmp#7999中的子件
***/
delete #tmp8999
set @id=(select min(autoid)from #tmp7999)
while @id<=(select max(autoid)from #tmp7999 )
begin
insert into #tmp8999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp7999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp7999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp7999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp9999 from #tmp1999 where 1=0
/***
第9次循环,查找tmp#8999中的子件
***/
delete #tmp9999
set @id=(select min(autoid)from #tmp8999)
while @id<=(select max(autoid)from #tmp8999 )
begin
insert into #tmp9999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
select opcomponentid , bomid, sortseq , componentid,
(baseqtYn*(select baseqtyn from #tmp8999 where autoid=@id )) as baseqitn
, baseQtyD from bom_opcomponent
----查询BOM子表并插入到Tmp7999中
where BomId =(select MAX( BomId) as bomid from bom_parent
where ParentId =(select ComponentId from #tmp8999 where AutoId=@id ) ))
set @id=@id+1
end select * into #tmp1 from #tmp1999 where 1=0
set @id=(select count(autoid) from #tmp9999 )
if @id=0
begin
delete #tmp1
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp1999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp2999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp3999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp4999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp5999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp6999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp7999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp8999)
insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
(select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp9999)
end /***
select * from #tmp1
where componentid='35547' select * from bas_part
where invcode='3020900005' partid='33857'
***/

用友U8按BOM计算销售订单物料需求SQL代码 第一稿的更多相关文章

  1. C4C销售订单行项目价格维护方法

    需求很简单,能够创建销售订单,在行项目里添加产品,带出价格来,同时把总价显示在销售订单抬头区域. 如下图所示: 下面是具体配置. Business Configuration里,点击Sales Ord ...

  2. 销售订单(SO)-API-创建销售订单

    创建销售订单API主要注意几点: 初始化环境变量:fnd_global.apps_initialize(); mo_global.init('ONT'); mo_global.set_policy_c ...

  3. 订单BOM、销售BOM、标准BOM

    订单BOM.销售BOM.标准BOM   訂單BOM: 是實際生產時用的BOM, 在標準BOM和銷售BOM基礎上增減物料的BOM銷售BOM: 是為特定客戶設定的BOM, 在主檔數據層次上的BOM, 在生 ...

  4. 订单BOM与销售BOM的区别

    訂單BOM: 是實際生產時用的BOM, 在標準BOM和銷售BOM基礎上增減物料的BOM 銷售BOM: 是為特定客戶設定的BOM, 在主檔數據層次上的BOM, 在生產時是帶到訂單BOM中去的. 標準BO ...

  5. 主管发话:一周搞不定用友U8 ERP跨业务数据分析,明天就可以“毕业”了

    随着月末来临,又到了汇报总结的时刻. (图片来自网络) 到了这个特殊时期,你的老板就一定想要查看企业整体的运转情况.销售业绩.客户实况分析.客户活跃度.Top10 sales. 产品情况.订单处理情况 ...

  6. 万物皆可集成系列:低代码释放用友U8+深度价值(2)—数据拓展应用

    在上一篇内容我们介绍了如何利用低代码开发套件实现低代码应用与U8+系统的对接集成,本次给大家带来的是如何将用友U8+系统中的数据进行价值扩展和实际应用. 我们以生产物料齐套分析为例来说明如何利用低代码 ...

  7. [SAP ABAP开发技术总结]SD销售订单定价过程

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. Netsharp快速入门(之13) 销售管理(单据流转 销售订单生成发货单)

    作者:秋时 杨昶   转载须说明出处 4.5     单据流转 4.5.1  单据流转的目的 单据流转主要为了实现业务关系的流转,并记录相互之间的关系.例如从销售订单生成销货单,两张单据之间有对应的关 ...

  9. 用友U8.70安装说明

    用友U8.70安装说明 U8.70安装说明一.安装前注意事项:1.       在安装U870之前,我们推荐您确保当前计算机操作系统是“干净”的,即计算机在安装过操作系统和更新过必要的系统补丁后没有安 ...

随机推荐

  1. ReaderWriterLock类(转)

    ReaderWriterLock类 通常来讲,一个类型的实例对于并行的读操作是线程安全的,但是并行地更新操作则不是(并 行地读和更新也不是). 这对于资源也是一样的,比如一个文件.当保护类型的实例安全 ...

  2. IIS中访问自己开发的Webservice site就自动停止,尝试重启IIS和重启服务器都不能解决。

    今天在加班的时候发现一个奇怪的问题,IIS里面我们自己开发的Webservice site一访问就自动停止.尝试重启IIS和重启服务器都不能解决.后台windows events报错信息是The Mo ...

  3. Java笔记(七)……函数

    函数的定义 定义在类中具有特定功能的一段独立小程序,也称方法. 函数的格式 1: 修饰符 返回值类型 函数名(参数类型 形式参数1,参数类型 形式参数2,) 2: { 3: 执行语句; 4: retu ...

  4. Visual Studio 2013中的新项目对话框

    在Visual Studio 2013,我们推出了添加新的项目对话框. 此对话框取代了是曾在2012年这个的对话框作品,所有ASP.NET项目(MVC,Web窗体和Web API). 这就是我们如何提 ...

  5. xp系统下网络打印机怎么设置

    亲测,可行 打印机共享可以有效节约办公资源,提高办公效率.可是还有很多朋友不知道怎么设置,我们这里讲一下网络打印机的设置方法. 1.我们点开桌面左下角的开始菜单,选择“打印机和传真” 2.我们右击某个 ...

  6. POJ3356 – AGTC(区间DP&&编辑距离)

    题目大意 给定字符串X和Y,可以对字符串进行一下三种操作: 1.删除一个字符 2.插入一个字符 3.替换一个字符 每个操作代价是1,问运用以上三种操作把X变为Y所需的最小步数是多少? 题解 定义dp[ ...

  7. Redis以及Redis的php扩展安装无错版

    安装Redis 下载最新的 官网:http://redis.io/  或者  http://code.google.com/p/redis/downloads/list 第一步:下载安装编译 #wge ...

  8. 【转】Vim 常用命令总结

    使用 Vim 的时间不长,但如今已经离不开熟悉的 Vim 编辑模式了. Vim 的学习曲线是非常陡的,一开始学习的时候,面对很多的操作命令要去记住,常常望而却步. 其实,只要记住一些常用的命令,加之在 ...

  9. Python队列服务 Python RQ Functions from the __main__ module cannot be processed by workers.

    在使用Python队列服务 Python RQ 时候的报错: Functions from the __main__ module cannot be processed by workers. 原因 ...

  10. HTML5终极备忘大全

    二.文字备忘之标签 HTML5中新增的标签 <article> 定义文章 <aside> 定义页面内容旁边的内容 <audio> 定义声音内容 <canvas ...