日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
遍歷BOM表的SQL函數(shù)

SQL函數(shù)的種類很多,實現(xiàn)的功能也不太一樣。下面為您介紹的是用于遍歷BOM表的SQL函數(shù),希望可以讓您對SQL函數(shù)有更多的了解。

成都創(chuàng)新互聯(lián)歡迎咨詢:18980820575,為您提供成都網(wǎng)站建設網(wǎng)頁設計及定制高端網(wǎng)站建設服務,成都創(chuàng)新互聯(lián)網(wǎng)頁制作領域10多年,包括成都混凝土攪拌站等多個行業(yè)擁有豐富的網(wǎng)站維護經(jīng)驗,選擇成都創(chuàng)新互聯(lián),為企業(yè)錦上添花。

表結構如下:
ptype subptype amount
a  a.120
a  a.2 15
a  a.3 10
a. 1 a.1.1 20
a.1a.1.2  15
a.1 a.1.330
a.2 a.2.110
a.2 a.2.2 20
a.1.1 a.1.1.1 45
a.1.1 a.1.1.2 15
a.2.1 a.2.1.1 20
a.2.2 a.2.2.1 13

 
 
 
  1. create table matgroup(parentgroup varchar(50),childgroup varchar(50), mount float)  
  2.  
  3. insert into matgroup   
  4. select 'a',  'a.1',20  
  5. union select 'a',  'a.2', 15  
  6. union select 'a',  'a.3', 10  
  7. union select 'a.1', 'a.1.1', 20  
  8. union select 'a.1','a.1.2',  15  
  9. union select 'a.1', 'a.1.3',30  
  10. union select 'a.2', 'a.2.1',10  
  11. union select 'a.2', 'a.2.2', 20  
  12. union select 'a.1.1', 'a.1.1.1', 45  
  13. union select 'a.1.1', 'a.1.1.2', 15  
  14. union select 'a.2.1' ,'a.2.1.1', 20  
  15. union select 'a.2.2', 'a.2.2.1', 13  

函數(shù)如下:

 
 
 
  1. create FUNCTION fn_aaa (@matgroup varchar(50),@mount int )  
  2. RETURNS @retPLExpand TABLE (parentgroup varchar(50),childgroup varchar(50), mount float)  
  3.  
  4. AS  
  5. BEGIN  
  6. DECLARE @RowsAdded int  
  7. declare @PLExpand Table (parentgroup varchar(50),childgroup varchar(50), mount float,processed tinyint default(0))  
  8.  
  9. INSERT @PLExpand  
  10.  SELECT b.parentgroup,b.childgroup, @mount*b.mount, 0  
  11.  FROM matgroup b   
  12.  WHERE b.parentgroup=@matgroup  
  13. SET @RowsAdded = @@rowcount  
  14.  
  15. -- While new employees were added in the previous iteration  
  16.  
  17. WHILE @RowsAdded > 0  
  18.  
  19. BEGIN  
  20. /*Mark all employee records whose direct reports are going to be   
  21. found in this iteration with processed=1.*/  
  22. UPDATE @PLExpand  
  23. SET processed = 1 
  24. WHERE processed = 0 
  25.  
  26. -- Insert employees who report to employees marked 1.  
  27. INSERT @PLExpand  
  28. SELECT a.parentgroup,a.childgroup,a.mount*b.mount , 0  
  29. FROM matgroup a inner join @PLExpand b on a.parentgroup=b.childgroup  
  30.   where b.processed = 1 
  31.  
  32. SET @RowsAdded = @@rowcount  
  33. /*Mark all employee records whose direct reports have been found  
  34. in this iteration.*/  
  35.  
  36. UPDATE @PLExpand  
  37. SET processed = 2 
  38. WHERE processed = 1 
  39. END  
  40.  
  41. -- copy to the result of the function the required columns  
  42. INSERT @retPLExpand  
  43. SELECT parentgroup,childgroup,mount  
  44. FROM @PLExpand  
  45. RETURN  
  46. END  

調(diào)用方法如下:
select * from fn_aaa('a.1')
意思是找出a.1下的所有兒子及孫子.
 

【編輯推薦】

動態(tài)sql中使用臨時表的實例

Oracle存儲過程使用動態(tài)SQL

SQL Server刪除視圖的兩種方法

SQL Server視圖的使用

sql server表格變量的用法


網(wǎng)站名稱:遍歷BOM表的SQL函數(shù)
當前URL:http://m.5511xx.com/article/cccosdd.html