SBO部分SQL查询奉献
生活随笔
收集整理的這篇文章主要介紹了
SBO部分SQL查询奉献
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
產(chǎn)品生產(chǎn)主計(jì)劃 SELECT T0.MsnCode AS '計(jì)劃單號(hào)', T1.ItemCode, T2.itemname AS '產(chǎn)品名稱',T1.Quantity as '生產(chǎn)數(shù)量', T2.onhand,T2.onorder as '已下單',T1.StartDate, T1.EndDate, T1.BaseDocNum as '訂單號(hào)',T1.BaseDue as '完工日期',T1.ParentCode as '產(chǎn)品名' FROM OMSN T0
INNER JOIN MSN3 T1 ON T0.AbsEntry = T1.AbsEntry
INNER JOIN OITM T2 ON T2.ITEMCODE=T1.ITEMCODE
?WHERE (T0.MsnCode = N'[%0]' OR '[%0]' = '') AND (T1.ItemCode = N'[%1]' OR '[%1]' = '') AND (T1.StartDate = CONVERT(DATETIME, '[%2]', 112) OR '[%2]' = '') AND T2.TREETYPE='p' 材料領(lǐng)用計(jì)劃 SELECT T0.MsnCode AS '計(jì)劃單號(hào)', T1.ItemCode, T2.itemname AS '產(chǎn)品名稱',T1.Quantity as '生產(chǎn)數(shù)量', T2.onhand,t2.Onorder as '已訂購(gòu)',T1.StartDate, T1.EndDate, T1.BaseDocNum as '訂單號(hào)',T1.BaseDue as '完工日期',T1.ParentCode as '產(chǎn)品名' FROM OMSN T0
INNER JOIN MSN3 T1 ON T0.AbsEntry = T1.AbsEntry
INNER JOIN OITM T2 ON T2.ITEMCODE=T1.ITEMCODE
?WHERE (T0.MsnCode = N'[%0]' OR '[%0]' = '') AND (T1.ItemCode = N'[%1]' OR '[%1]' = '') AND (T1.StartDate = CONVERT(DATETIME, '[%2]', 112) OR '[%2]' = '') AND T2.TREETYPE='N' 多層BOM
--------中間表---
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bomt]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bomt]
GO CREATE TABLE [dbo].[bomt] (
[parent_item] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[itemname] [nvarchar] (100) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[sl] [numeric](19, 6) NULL ,
[dw] [nvarchar] (8) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[ck] [nvarchar] (8) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[Price] [numeric](19, 6) NULL ,
[jghb] [nvarchar] (3) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[pl] [smallint] NULL ,
[ceci] [int] NULL ,
[fhf] [char] (1) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[scbs] [char] (2) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[path] [nvarchar] (800) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gw] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gx] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[cardcode] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gysn] [nvarchar] (200) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gc] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[hw] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[itemwm] [nvarchar] (200) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[tzs] [nvarchar] (100) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[scf] [nvarchar] (50) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[flf] [nvarchar] (10) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[mjg] [numeric](18, 6) NULL ,
[mje] [numeric](18, 6) NULL ,
[je] [numeric](18, 6) NULL ,
[xjg] [numeric](18, 6) NULL ,
[rjg] [numeric](18, 6) NULL ,
[rje] [numeric](18, 6) NULL ,
[bje] [numeric](18, 6) NULL
) ON [PRIMARY]
GO -----------存儲(chǔ)過程
CREATE proc BOM
@mj nvarchar(20)
as
begin
delete from bomt
declare @l int,@bz int
set @l=0
INSERT INTO bomt
????? (parent_item, itemname, itemwm,sl, dw, ck, Price, jghb, ceci, scbs, path)
select a.itemcode ,a.itemname,a.FrgnName,1,a.InvntryUom,a.DfltWH,a.LstEvlPric,'RMB',@l,a.TreeType,right(space(20)+a.itemcode,20)
from oitm a
where a.itemcode=@mj
?----
set @bz=(select T1.Qauntity from oitt t1 where t1.code=@mj)
while @@rowcount>0
???? begin
????? set @l=@l+1
????? INSERT INTO bomt
?????? (parent_item, itemname,itemwm, sl, dw, ck, Price, jghb, ceci, scbs, path,pl,fhf,hw)
????? select i.itemcode,i.itemname,i.FrgnName,a.Quantity, i.InvntryUom,a.Warehouse, a.Price, a.Currency,@l,i.TreeType,path+','+str(a.ChildNum,3)+right(space(20)+i.itemcode,20),a.PriceList,a.IssueMthd,i.sww
????? from (SELECT T1.Father, T1.ChildNum, T1.Code, T1.Quantity/ T0.Qauntity as Quantity , T1.Warehouse, T1.Price, T1.Currency, T1.PriceList, T1.Comment, T1.LogInstanc, T1.Uom,t1.IssueMthd FROM OITT T0? INNER JOIN ITT1 T1 ON T0.Code = T1.Father) a, bomt b,oitt c,oitm i
????? where? b.parent_item=c.code COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and c.code=a.father COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and a.code= i.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and b.ceci=@l-1
????? end
-- =============================================
-- 計(jì)算bom的準(zhǔn)確用量
-- =============================================
DECLARE @yl decimal(18,6),@path nvarchar(800),@cd int,@cec int DECLARE boms CURSOR
FOR SELECT? sl, path ,len(path),ceci FROM bomt where scbs='P' and ceci>0 -----獲取是生產(chǎn)件的數(shù)據(jù),根據(jù)層數(shù)逐階展開 --DECLARE @count smallint
--SELECT @count = 1 OPEN boms
FETCH NEXT FROM boms? INTO @yl,@path,@cd,@cec
WHILE (@@fetch_status <> -1)
BEGIN
-------------更新用量
UPDATE bomt
SET sl=@yl*sl
WHERE ceci=@cec+1 ------制定下一層,即限制它的第一階子件,而不往下階延伸
???????????????????? and left(path,@cd)=@path
??????????????
??????????????? FETCH NEXT FROM boms? INTO @yl,@path,@cd,@cec END CLOSE boms
DEALLOCATE boms
--------顯示
select ceci as 層次,parent_item as 物料, itemname as 物料名稱, @bz*sl as 標(biāo)準(zhǔn)設(shè)計(jì)數(shù)量, dw as 單位, ck as 倉(cāng)庫, fhf as 發(fā)貨方法,scbs as BOM類型 from bomt order by path
end
GO
INNER JOIN MSN3 T1 ON T0.AbsEntry = T1.AbsEntry
INNER JOIN OITM T2 ON T2.ITEMCODE=T1.ITEMCODE
?WHERE (T0.MsnCode = N'[%0]' OR '[%0]' = '') AND (T1.ItemCode = N'[%1]' OR '[%1]' = '') AND (T1.StartDate = CONVERT(DATETIME, '[%2]', 112) OR '[%2]' = '') AND T2.TREETYPE='p' 材料領(lǐng)用計(jì)劃 SELECT T0.MsnCode AS '計(jì)劃單號(hào)', T1.ItemCode, T2.itemname AS '產(chǎn)品名稱',T1.Quantity as '生產(chǎn)數(shù)量', T2.onhand,t2.Onorder as '已訂購(gòu)',T1.StartDate, T1.EndDate, T1.BaseDocNum as '訂單號(hào)',T1.BaseDue as '完工日期',T1.ParentCode as '產(chǎn)品名' FROM OMSN T0
INNER JOIN MSN3 T1 ON T0.AbsEntry = T1.AbsEntry
INNER JOIN OITM T2 ON T2.ITEMCODE=T1.ITEMCODE
?WHERE (T0.MsnCode = N'[%0]' OR '[%0]' = '') AND (T1.ItemCode = N'[%1]' OR '[%1]' = '') AND (T1.StartDate = CONVERT(DATETIME, '[%2]', 112) OR '[%2]' = '') AND T2.TREETYPE='N' 多層BOM
--------中間表---
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[bomt]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[bomt]
GO CREATE TABLE [dbo].[bomt] (
[parent_item] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[itemname] [nvarchar] (100) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[sl] [numeric](19, 6) NULL ,
[dw] [nvarchar] (8) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[ck] [nvarchar] (8) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[Price] [numeric](19, 6) NULL ,
[jghb] [nvarchar] (3) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[pl] [smallint] NULL ,
[ceci] [int] NULL ,
[fhf] [char] (1) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[scbs] [char] (2) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[path] [nvarchar] (800) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gw] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gx] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[cardcode] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gysn] [nvarchar] (200) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[gc] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[hw] [nvarchar] (20) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[itemwm] [nvarchar] (200) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[tzs] [nvarchar] (100) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[scf] [nvarchar] (50) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[flf] [nvarchar] (10) COLLATE SQL_Latin1_General_CP850_CI_AS NULL ,
[mjg] [numeric](18, 6) NULL ,
[mje] [numeric](18, 6) NULL ,
[je] [numeric](18, 6) NULL ,
[xjg] [numeric](18, 6) NULL ,
[rjg] [numeric](18, 6) NULL ,
[rje] [numeric](18, 6) NULL ,
[bje] [numeric](18, 6) NULL
) ON [PRIMARY]
GO -----------存儲(chǔ)過程
CREATE proc BOM
@mj nvarchar(20)
as
begin
delete from bomt
declare @l int,@bz int
set @l=0
INSERT INTO bomt
????? (parent_item, itemname, itemwm,sl, dw, ck, Price, jghb, ceci, scbs, path)
select a.itemcode ,a.itemname,a.FrgnName,1,a.InvntryUom,a.DfltWH,a.LstEvlPric,'RMB',@l,a.TreeType,right(space(20)+a.itemcode,20)
from oitm a
where a.itemcode=@mj
?----
set @bz=(select T1.Qauntity from oitt t1 where t1.code=@mj)
while @@rowcount>0
???? begin
????? set @l=@l+1
????? INSERT INTO bomt
?????? (parent_item, itemname,itemwm, sl, dw, ck, Price, jghb, ceci, scbs, path,pl,fhf,hw)
????? select i.itemcode,i.itemname,i.FrgnName,a.Quantity, i.InvntryUom,a.Warehouse, a.Price, a.Currency,@l,i.TreeType,path+','+str(a.ChildNum,3)+right(space(20)+i.itemcode,20),a.PriceList,a.IssueMthd,i.sww
????? from (SELECT T1.Father, T1.ChildNum, T1.Code, T1.Quantity/ T0.Qauntity as Quantity , T1.Warehouse, T1.Price, T1.Currency, T1.PriceList, T1.Comment, T1.LogInstanc, T1.Uom,t1.IssueMthd FROM OITT T0? INNER JOIN ITT1 T1 ON T0.Code = T1.Father) a, bomt b,oitt c,oitm i
????? where? b.parent_item=c.code COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and c.code=a.father COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and a.code= i.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS
??????????? and b.ceci=@l-1
????? end
-- =============================================
-- 計(jì)算bom的準(zhǔn)確用量
-- =============================================
DECLARE @yl decimal(18,6),@path nvarchar(800),@cd int,@cec int DECLARE boms CURSOR
FOR SELECT? sl, path ,len(path),ceci FROM bomt where scbs='P' and ceci>0 -----獲取是生產(chǎn)件的數(shù)據(jù),根據(jù)層數(shù)逐階展開 --DECLARE @count smallint
--SELECT @count = 1 OPEN boms
FETCH NEXT FROM boms? INTO @yl,@path,@cd,@cec
WHILE (@@fetch_status <> -1)
BEGIN
-------------更新用量
UPDATE bomt
SET sl=@yl*sl
WHERE ceci=@cec+1 ------制定下一層,即限制它的第一階子件,而不往下階延伸
???????????????????? and left(path,@cd)=@path
??????????????
??????????????? FETCH NEXT FROM boms? INTO @yl,@path,@cd,@cec END CLOSE boms
DEALLOCATE boms
--------顯示
select ceci as 層次,parent_item as 物料, itemname as 物料名稱, @bz*sl as 標(biāo)準(zhǔn)設(shè)計(jì)數(shù)量, dw as 單位, ck as 倉(cāng)庫, fhf as 發(fā)貨方法,scbs as BOM類型 from bomt order by path
end
GO
轉(zhuǎn)載于:https://blog.51cto.com/johnny/32681
總結(jié)
以上是生活随笔為你收集整理的SBO部分SQL查询奉献的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到鬼请吃饭怎么回事
- 下一篇: 梦到买车开车是什么意思