1. drop table #tmp1999
  2. drop table #tmp2999
  3. drop table #tmp3999
  4. drop table #tmp4999
  5. drop table #tmp5999
  6. drop table #tmp6999
  7. drop table #tmp7999
  8. drop table #tmp8999
  9. drop table #tmp9999
  10. drop table #tmp1
  11.  
  12. create table #tmp1999
  13. (
  14. [autoid] [int] IDENTITY(1,1) NOT NULL,
  15. [opcomponentid] [nvarchar](100) NULL,
  16. [bomid] [nvarchar](100) NULL,
  17. [sortseq] [nvarchar](20) NULL,
  18. [componentid] [nvarchar](100) NULL,
  19. [baseqtyn] [decimal](10, 4) NULL,
  20. [baseQtyD] [decimal](10, 4) NULL
  21.  
  22. )
  23.  
  24. delete #tmp1999
  25.  
  26. declare @id int
  27. set @id=(select min(autoid) from SO_SODetails /*where cInvCode='1C00601009'*/ )
  28. ---声明一个变量,销售明细里面最小的ID号赋值给变量
  29. while(@id)<=(select max(autoid) from SO_SODetails /*where cInvCode='1C00601009'*/)
  30. ---当@id<=销售订单明细表最大ID时,循环
  31. begin
  32. insert into #tmp1999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  33. select opcomponentid , bomid, sortseq , componentid,
  34. (baseqtYn*(select iQuantity from SO_SODetails where autoid=@id )) as baseqitn,
  35. baseQtyD from bom_opcomponent
  36. ----查询BOM子表并插入到#Tmp1999
  37. where BomId =(
  38. select MAX( BomId) as bomid from bom_parent
  39.  
  40. where ParentId = (
  41. select partid from bas_part
  42. where InvCode = (
  43. select cinvcode from SO_SODetails
  44. where AutoID=@id))))
  45.  
  46. set @id=@id+1
  47. end
  48.  
  49. ----根据#tmp1999创建一个数据结构相同的表 #tmp2999
  50. select * into #tmp2999 from #tmp1999 where 1=0
  51.  
  52. /***
  53. 第二次循环,查找tmp#1999中的子件
  54. ***/
  55. delete #tmp2999
  56. set @id=(select min(autoid)from #tmp1999)
  57. while @id<=(select max(autoid)from #tmp1999 )
  58. begin
  59. insert into #tmp2999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  60. select opcomponentid , bomid, sortseq , componentid,
  61. (baseqtYn*(select baseqtyn from #tmp1999 where autoid=@id )) as baseqitn
  62. , baseQtyD from bom_opcomponent
  63. ----查询BOM子表并插入到Tmp2999
  64. where BomId =(select MAX( BomId) as bomid from bom_parent
  65. where ParentId =(select ComponentId from #tmp1999 where AutoId=@id ) ))
  66. set @id=@id+1
  67. end
  68.  
  69. select * into #tmp3999 from #tmp1999 where 1=0
  70. /***
  71. 第三次循环,查找tmp#2999中的子件
  72. ***/
  73. delete #tmp3999
  74. set @id=(select min(autoid)from #tmp2999)
  75. while @id<=(select max(autoid)from #tmp2999 )
  76. begin
  77. insert into #tmp3999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  78. select opcomponentid , bomid, sortseq , componentid,
  79. (baseqtYn*(select baseqtyn from #tmp2999 where autoid=@id )) as baseqitn
  80. , baseQtyD from bom_opcomponent
  81. ----查询BOM子表并插入到Tmp3999
  82. where BomId =(select MAX( BomId) as bomid from bom_parent
  83. where ParentId =(select ComponentId from #tmp2999 where AutoId=@id ) ))
  84. set @id=@id+1
  85. end
  86.  
  87. select * into #tmp4999 from #tmp1999 where 1=0
  88. /***
  89. 第四次循环,查找tmp#3999中的子件
  90. ***/
  91. delete #tmp4999
  92. set @id=(select min(autoid)from #tmp3999)
  93. while @id<=(select max(autoid)from #tmp3999 )
  94. begin
  95. insert into #tmp4999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  96. select opcomponentid , bomid, sortseq , componentid,
  97. (baseqtYn*(select baseqtyn from #tmp3999 where autoid=@id )) as baseqitn
  98. , baseQtyD from bom_opcomponent
  99. ----查询BOM子表并插入到Tmp4999
  100. where BomId =(select MAX( BomId) as bomid from bom_parent
  101. where ParentId =(select ComponentId from #tmp3999 where AutoId=@id ) ))
  102. set @id=@id+1
  103. end
  104.  
  105. select * into #tmp5999 from #tmp1999 where 1=0
  106. /***
  107. 第四次循环,查找tmp#4999中的子件
  108. ***/
  109. delete #tmp5999
  110. set @id=(select min(autoid)from #tmp4999)
  111. while @id<=(select max(autoid)from #tmp4999 )
  112. begin
  113. insert into #tmp5999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  114. select opcomponentid , bomid, sortseq , componentid,
  115. (baseqtYn*(select baseqtyn from #tmp4999 where autoid=@id )) as baseqitn
  116. , baseQtyD from bom_opcomponent
  117. ----查询BOM子表并插入到Tmp5999
  118. where BomId =(select MAX( BomId) as bomid from bom_parent
  119. where ParentId =(select ComponentId from #tmp4999 where AutoId=@id ) ))
  120. set @id=@id+1
  121. end
  122.  
  123. select * into #tmp6999 from #tmp1999 where 1=0
  124. /***
  125. 第六次循环,查找tmp#5999中的子件
  126. ***/
  127. delete #tmp6999
  128. set @id=(select min(autoid)from #tmp5999)
  129. while @id<=(select max(autoid)from #tmp5999 )
  130. begin
  131. insert into #tmp6999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  132. select opcomponentid , bomid, sortseq , componentid,
  133. (baseqtYn*(select baseqtyn from #tmp5999 where autoid=@id )) as baseqitn
  134. , baseQtyD from bom_opcomponent
  135. ----查询BOM子表并插入到Tmp5999
  136. where BomId =(select MAX( BomId) as bomid from bom_parent
  137. where ParentId =(select ComponentId from #tmp5999 where AutoId=@id ) ))
  138. set @id=@id+1
  139. end
  140.  
  141. select * into #tmp7999 from #tmp1999 where 1=0
  142. /***
  143. 第七次循环,查找tmp#6999中的子件
  144. ***/
  145. delete #tmp7999
  146. set @id=(select min(autoid)from #tmp6999)
  147. while @id<=(select max(autoid)from #tmp6999 )
  148. begin
  149. insert into #tmp7999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  150. select opcomponentid , bomid, sortseq , componentid,
  151. (baseqtYn*(select baseqtyn from #tmp6999 where autoid=@id )) as baseqitn
  152. , baseQtyD from bom_opcomponent
  153. ----查询BOM子表并插入到Tmp7999
  154. where BomId =(select MAX( BomId) as bomid from bom_parent
  155. where ParentId =(select ComponentId from #tmp6999 where AutoId=@id ) ))
  156. set @id=@id+1
  157. end
  158.  
  159. select * into #tmp8999 from #tmp1999 where 1=0
  160. /***
  161. 第八次循环,查找tmp#7999中的子件
  162. ***/
  163. delete #tmp8999
  164. set @id=(select min(autoid)from #tmp7999)
  165. while @id<=(select max(autoid)from #tmp7999 )
  166. begin
  167. insert into #tmp8999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  168. select opcomponentid , bomid, sortseq , componentid,
  169. (baseqtYn*(select baseqtyn from #tmp7999 where autoid=@id )) as baseqitn
  170. , baseQtyD from bom_opcomponent
  171. ----查询BOM子表并插入到Tmp7999
  172. where BomId =(select MAX( BomId) as bomid from bom_parent
  173. where ParentId =(select ComponentId from #tmp7999 where AutoId=@id ) ))
  174. set @id=@id+1
  175. end
  176.  
  177. select * into #tmp9999 from #tmp1999 where 1=0
  178. /***
  179. 第9次循环,查找tmp#8999中的子件
  180. ***/
  181. delete #tmp9999
  182. set @id=(select min(autoid)from #tmp8999)
  183. while @id<=(select max(autoid)from #tmp8999 )
  184. begin
  185. insert into #tmp9999 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)(
  186. select opcomponentid , bomid, sortseq , componentid,
  187. (baseqtYn*(select baseqtyn from #tmp8999 where autoid=@id )) as baseqitn
  188. , baseQtyD from bom_opcomponent
  189. ----查询BOM子表并插入到Tmp7999
  190. where BomId =(select MAX( BomId) as bomid from bom_parent
  191. where ParentId =(select ComponentId from #tmp8999 where AutoId=@id ) ))
  192. set @id=@id+1
  193. end
  194.  
  195. select * into #tmp1 from #tmp1999 where 1=0
  196. set @id=(select count(autoid) from #tmp9999 )
  197. if @id=0
  198. begin
  199. delete #tmp1
  200. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  201. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp1999)
  202. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  203. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp2999)
  204. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  205. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp3999)
  206. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  207. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp4999)
  208. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  209. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp5999)
  210. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  211. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp6999)
  212. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  213. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp7999)
  214. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  215. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp8999)
  216. insert into #tmp1 ( opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD)
  217. (select opcomponentid , bomid, sortseq , componentid, baseqtyn, baseQtyD from #tmp9999)
  218. end
  219.  
  220. /***
  221. select * from #tmp1
  222. where componentid='35547'
  223.  
  224. select * from bas_part
  225. where invcode='3020900005' partid='33857'
  226. ***/

用友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. hadoop学习笔记——基础知识及安装

    1.核心 HDFS  分布式文件系统    主从结构,一个namenoe和多个datanode, 分别对应独立的物理机器 1) NameNode是主服务器,管理文件系统的命名空间和客户端对文件的访问操 ...

  2. [King.yue]Ext.JS 弹出窗体取值赋值

    //从Grid取值 var name = Ext.getCmp(gridGridID).getView().getSelectionModel().getSelection()[0].data.Nam ...

  3. [codevs3862]竞赛班的垃圾处理

    题目描述 Description 竞赛班的师弟们都很懒,每个人都不喜欢倒垃圾,结果垃圾就会跟师兄的RP一样越堆越多,当然,老师时不时就会叫他们去倒垃圾.由于他们真的很懒,他们只会直接将垃圾桶最上面袋拿 ...

  4. NOIP2003 侦探推理

    题二    侦探推理 [问题描述] 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯( ...

  5. Docker系列(五)OVS+Docker网络打通示例

    环境说明 两个虚拟机 操作系统Centos7 DOcker版本1.8 脚本内容: 1  4  7  10  19  27  32    33  39   -j ACCEPT 47    48  # R ...

  6. 【Java基础】Java中的持久属性集Properties

    Properties 类的介绍 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串.一个属性列表可包含另一个属性列 ...

  7. pytho

    字符串格式化:求模操作符%可以用来将其他值转换为包含转换标志的字符串,对值进行不同方法的格式化,左右对齐,字段宽度精度,增加符号,左填充数字 字符串方法join split istitle capit ...

  8. 【荐】Redis学习资料汇总

    Redis学习手册(目录) - Stephen_Liu - 博客园 Redis 命令参考 — Redis 命令参考 Redis_php 学习 - 简单--生活 - 博客园

  9. 教程-EhLib70的安装方法

    1.下载EhLib 5.2包2.将Common文件下的文件全部复制到DELPHI7目录下.3.打开DELPHI7.0程序:打开DclEhLib70.dpk文件包点“编译”->“安装”打开EhLi ...

  10. 从CR线下活动学到的:如何组织一个小的线下活动

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf 周末在腾讯组织了GR,活动达到了预期的收获,从这次活动我主 ...