0% found this document useful (0 votes)
36 views5 pages

Usp

The document declares several variables used for filtering and sorting data from a SQL query. It then defines a table variable and performs a UNION of two SELECT queries from different tables to populate the table variable. The first query retrieves data from the CH_REC_TASK and related tables for stock requisition tasks. The second query retrieves similar data from the ORDR and RDR1 tables for sales orders. Various filters are applied to both queries based on the declared variables.

Uploaded by

ken guo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Usp

The document declares several variables used for filtering and sorting data from a SQL query. It then defines a table variable and performs a UNION of two SELECT queries from different tables to populate the table variable. The first query retrieves data from the CH_REC_TASK and related tables for stock requisition tasks. The second query retrieves similar data from the ORDR and RDR1 tables for sales orders. Various filters are applied to both queries based on the declared variables.

Uploaded by

ken guo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

declare @u28 varchar(10) = N'' --分支

declare @u13 nvarchar(200) = N'' -- 客户编码


declare @u32 varchar(20) = N'' -- 成本中心
declare @u18 int = null -- 备货单号
declare @u11 int = null --销售单号
declare @u34 nvarchar(200) = N'' -- 客户合同号
declare @u3 nvarchar(200) = N'' --产品编码
declare @u26 nvarchar(100) = N'' --图号
declare @u21 datetime --订单日期从
declare @u22 datetime --订单日期到
declare @u29 int = 0 --排序类型
declare @u35 char = N'Y' -- 仅显示需要排产的产品明细

--DECLARE @U3 AS VARCHAR(20)


--,@U18 AS VARCHAR(20)
--,@U11 AS VARCHAR(20)
--,@U13 AS VARCHAR(20)
--,@U28 AS VARCHAR(20)
--,@U29 AS VARCHAR(20)
--,@U26 AS VARCHAR(20)
--,@U32 AS VARCHAR(20)
--,@U34 AS VARCHAR(20)
--,@U35 AS VARCHAR(20)
--,@U21 AS DATETIME
--,@U22 AS DATETIME

--SET @U21 = '20220101'


--SET @U22 = '20220630'

--DECLARE @Table AS TABLE (


--DocType varchar(20)
--,U_Branch varchar(20)
--,ItemCode varchar(20)
--,ItemName nvarchar(100)
--, NumAtCard varchar(100)
--,U_DrawNo varchar(100)
--, GYFA varchar(20)
--,PlannedQty decimal(18,6)
--,ShipDate datetime
--,ck VARCHAR
--,AdiveQty decimal(18,6)
--,AdiveQtyNonEdit decimal(18,6)
--,OrdrMulti decimal(18,6)
----,Warehouse varchar(6)
----,PostDate datetime
--,StartDate datetime
--,LeadTime int
--,IssueQty decimal(18,6)
--,ToWH varchar(6)
--, AVAQty decimal(18,6)
--, OnHand decimal(18,6)
--,OnOrder decimal(18,6)
--,IsCommited decimal(18,6)
--, AllOnHand decimal(18,6)
-- ,OcrCode varchar(20)
--,DocDate datetime
--,DocEntry varchar(20)
--,SoEntry varchar(20)
--,VisOrder varchar(20)
--,U_SoEntry varchar(20)
--,CardCode varchar(20)
--,CardName nvarchar(100)
--,BpChCode varchar(20)
--,BpChName nvarchar(100)
--,U_CardType varchar(20)
--)

--INSERT INTO @Table

SELECT t.DocType,
t.U_Branch,
t.ItemCode,
t.Dscription ItemName,
T.NumAtCard,
t3.U_DrawNo,
t5.code,
t.Quantity,
t.ShipDate,
'N' ck,
--Cast (0 AS INT) BackBom,
--t.BomEntry,
CASE
WHEN t.Quantity-Isnull (t.IssueQty, 0)>0 THEN t.Quantity-Isnull
(t.IssueQty, 0)
ELSE 0
END AdiveQty,
CASE
WHEN t.Quantity-Isnull (t.IssueQty, 0)>0 THEN t.Quantity-Isnull
(t.IssueQty, 0)
ELSE 0
END AdiveQtyNonEdit, --根据销售订单,备货订单成品数量以及已下发数量,作为生
产订单理论数量和浮动数量的依据
t3.OrdrMulti,
CASE
WHEN t.Quantity-Isnull (t.IssueQty, 0)>0
AND t1.U_CardType='1' THEN Cast (Dateadd (DAY, -15, t.ShipDate)
AS DATE)
WHEN t.Quantity-Isnull (t.IssueQty, 0)>0
AND t1.U_CardType='2' THEN Cast (Dateadd (DAY, -8, t.ShipDate)
AS DATE)
ELSE t.ShipDate
END StartDate,
CASE
WHEN t1.U_CardType='1' THEN 14
WHEN t1.U_CardType='2' THEN 7
ELSE 0
END LeadTime,
t.IssueQty,
T.ToWH,
T.AVAQty,
T.OnHand,
T.OnOrder,
T.IsCommited,
t3.OnHand AllOnHand,
t.OcrCode,
t.DocDate,
t.DocEntry,
t.SoEntry,
t.VisOrder,
t.U_SoEntry,
t.CardCode,
t1.CardName,
t.BpChCode,
t2.CardName BpChName,
t1.U_CardType
FROM (
--库存备货单
SELECT 'CHRECTASK' DocType,
t.U_Branch,
T.U_DocDate DocDate,
T.DocEntry,
NULL SoEntry,
T.U_NumAtCard NumAtCard,
T1.LineId as visorder,
NULL U_SoEntry,
T1.U_ItemCode ItemCode,
T1.U_ItemName Dscription,
--Cast(T3.DocEntry AS NVARCHAR) BomEntry,
T1.U_Quantity Quantity,
Isnull(t6.IssueQty, 0) IssueQty,
t8.ToWH,
t9.OnHand,
t9.OnOrder,
t9.IsCommited,
(t9.OnHand+t9.OnOrder-t9.IsCommited) AVAQty,
t8.OcrCode,
T1.U_ShipDate ShipDate,
T.U_CardCode CardCode,
T.U_BpCode BpChCode
FROM [@CH_REC_TASK] t
INNER JOIN [@CH_REC_TASK_1] t1 ON T.DocEntry=T1.DocEntry
INNER JOIN oitm t2 ON t1.U_ItemCode=t2.ItemCode
LEFT JOIN oitt t8 ON t1.U_ItemCode=t8.Code
LEFT JOIN oitw t9 ON t1.U_ItemCode=t9.ItemCode
AND t8.ToWH =t9.WhsCode
LEFT JOIN OCRD t4 ON t.U_BpCode=t4.CardCode
--LEFT JOIN [@CH_BACK_BOM] t3 ON t1.DocEntry =t3.U_TaskNo
-- AND t1.LineId =t3.U_LineId
-- AND t1.U_ItemCode=t3.U_ItemCode
LEFT OUTER JOIN (SELECT U_TaskNo,
U_TaskId,
ItemCode,
Sum (CASE WHEN Status='L' THEN CmpltQty+RjctQty
ELSE owor.PlannedQty
END) IssueQty
FROM OWOR
WHERE Status<>'C'
AND ISNULL(U_BaseEntry,'') = ''
-- AND Isnull (OriginNum, -1)>0
GROUP BY ItemCode,U_TaskNo,U_TaskId) t6 ON t1.DocEntry
=t6.U_TaskNo
AND t1.LineId
=t6.U_TaskId
AND
t1.U_ItemCode=t6.ItemCode
WHERE T.Canceled ='N'
AND T.Status ='C'
AND T1.U_Quantity-Isnull(t6.IssueQty, 0)>0
AND (Isnull(@u3, '') =''
OR t1.U_ItemCode =@u3)
AND (Isnull(@u18, '') =''
OR t.DocEntry =@u18)
AND (Isnull(@u13, '') =''
OR t.U_CardCode =@u13)
AND (Isnull(@u28, '') =''
OR t.U_Branch =@u28)
AND (Isnull(@u26, '') =''
OR t2.U_DrawNo =@u26)
AND (Isnull(@u32, '') =''
OR t8.OcrCode =@u32)
AND (Isnull(@u34, '') =''
OR T.U_NumAtCard =@u34)
AND (Isnull(@u35, 'N') ='N'
OR t2.PrcrmntMtd ='M')
AND t.U_DocDate>=@u21
AND t.U_DocDate<=@u22
UNION
----销售订单
SELECT '17' DocType,
t.U_branch,
t.DocDate,
NULL DocEntry,
t.DocEntry SoEntry,
T.NumAtCard,
T1.LineNum Visorder,
T.U_SoEntry,
T1.ItemCode,
T1.Dscription,
--Cast(T3.DocEntry AS NVARCHAR) BomEntry,
T1.Quantity,
Isnull(t6.IssueQty, 0) IssueQty,
T8.ToWH,
T9.OnHand,
T9.OnOrder,
T9.IsCommited,
(t9.OnHand+t9.OnOrder-t9.IsCommited) AVAQty,
t8.OcrCode,
T1.ShipDate,
T.CardCode,
T.BPChCode
FROM ORDR t
INNER JOIN RDR1 t1 ON T.DocEntry=T1.DocEntry
INNER JOIN oitm t2 ON t1.ITEMCODE=t2.ItemCode
LEFT JOIN oitt t8 ON t1.ItemCode=t8.Code
LEFT JOIN OITW t9 ON T1.ItemCode=T9.ItemCode
AND T8.ToWH =T9.WhsCode
LEFT JOIN OCRD t4 ON t.BPChCode=t4.CardCode
--LEFT JOIN [@CH_BACK_BOM] t3 ON t1.DocEntry =t3.U_TaskNo
-- AND t1.LineNum=t3.U_LineId
-- AND t1.ItemCode =t3.U_ItemCode
LEFT OUTER JOIN (SELECT U_BaseEntry,
U_BaseLine,
ItemCode,
Sum (CASE
WHEN Status='L' THEN CmpltQty+RjctQty
ELSE owor.PlannedQty
END) IssueQty
FROM OWOR
WHERE Status<>'C'
-- AND Isnull (OriginNum, -1)>0
AND ISNULL(U_BaseEntry,'') <> ''
GROUP BY U_BaseEntry,U_BaseLine,ItemCode) t6 ON
t1.DocEntry =t6.U_BaseEntry
AND
t1.LineNum = t6.U_BaseLine
AND
t1.ItemCode =t6.ItemCode
WHERE T.Canceled ='N'
AND T.DocStatus <>'C'
AND ( ISNULL(T1.U_BackOrder,'N') = 'N' OR (T1.U_BackOrder = 'Y' AND
T.U_SoEntry IS NOT NULL))
AND t1.Quantity-Isnull(t6.IssueQty, 0)>0
AND (Isnull(@u3, '') =''
AND Isnull(t1.U_BackOrder, 'N') ='N'
OR t1.ItemCode =@u3)
AND (Isnull(@u11, '') =''
OR t.DocEntry =@u11)
AND (Isnull(@u13, '') =''
OR t.CardCode =@u13)
AND (Isnull(@u28, '') =''
OR t.U_Branch =@u28)
AND (Isnull(@u26, '') =''
OR t2.U_DrawNo =@u26)
AND (Isnull(@u32, '') =''
OR t8.OcrCode =@u32)
AND (Isnull(@u34, '') =''
OR t.NumAtCard =@u34)
AND (Isnull(@u35, 'N') ='N'
OR t2.PrcrmntMtd ='M')
AND t.DocDate>=@u21
AND t.DocDate<=@u22) t
LEFT JOIN ocrd t1 ON t.CardCode=t1.CardCode
LEFT JOIN ocrd t2 ON t.BpChCode=t2.CardCode
INNER JOIN oitm t3 ON t.ItemCode=t3.ItemCode
LEFT JOIN (SELECT A.Code,
B.U_ItemCode
FROM [@CH_MES_GYFA] a
INNER JOIN [@CH_MES_GYFA_2] b ON a.Code=b.Code
WHERE a.Canceled='N') t5 ON t.ItemCode=t5.U_ItemCode

ORDER BY CASE
WHEN @u29='0' THEN t.DocType
WHEN @u29='1' THEN t.ItemCode
WHEN @u29='2' THEN Cast(t.ShipDate AS NVARCHAR)
END

--SELECT *
--FROM @Table

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy