Anda di halaman 1dari 4

1.

SAP INVENTORY QUERY IN & OUT


<---------------------------------------Choose from date,To date and WareHouse--------------------------> Declare @FromDate Datetime Declare @ToDate Datetime Declare @Whse nvarchar(10) select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >='[%0]' select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]' select @Whse = Max(s2.Warehouse) from dbo.OINM S2 Where S2.Warehouse = '[%2]' Select @Whse as 'Warehouse', a.Itemcode, max(a.Dscription) as ItemName, sum(a.OpeningBalance) as OpeningBalance, sum(a.INq) as 'IN', sum(a.OUT) as OUT, ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing , (Select t.LastPurPrc from OITM t where t.ItemCode=a.Itemcode) as LastPurPrice, (Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM from ( Select N1.Warehouse, N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty)) as OpeningBalance, 0 as INq, 0 as OUT From dbo.OINM N1 Where N1.DocDate < @FromDate and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription Union All select N1.Warehouse, N1.Itemcode, N1.Dscription, 0 as OpeningBalance, sum(N1.inqty) , 0 as OUT From dbo.OINM N1 Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate and N1.Inqty >0 and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription Union All select N1.Warehouse, N1.Itemcode, N1.Dscription, 0 as OpeningBalance, 0 , sum(N1.outqty) as OUT From dbo.OINM N1 Where N1.DocDate >= @FromDate and N1.DocDate <=@ToDate and N1.OutQty >0 and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription) a, dbo.OITM I1 where a.ItemCode=I1.ItemCode Group By a.Itemcode Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0 Order By a.Itemcode <---------------------------------------To Filter WareHouse in above report--------------------------> Declare @FromDate Datetime Declare @ToDate Datetime Declare @Whse nvarchar(10) select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >='[%0]' select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]' select @Whse = Max(s2.Warehouse) from dbo.OINM S2 Where S2.Warehouse NOT IN ('01','02') Select @Whse as 'Warehouse', a.Itemcode, max(a.Dscription) as ItemName, sum(a.OpeningBalance) as OpeningBalance, sum(a.INq) as 'IN', sum(a.OUT) as OUT, ((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing , (Select t.LastPurPrc from OITM t where t.ItemCode=a.Itemcode) as LastPurPrice, (Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM from ( Select N1.Warehouse, N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty)) as OpeningBalance, 0 as INq, 0 as OUT From dbo.OINM N1

Where N1.DocDate < @FromDate and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription Union All select N1.Warehouse, N1.Itemcode, N1.Dscription, 0 as OpeningBalance, sum(N1.inqty) , 0 as OUT From dbo.OINM N1 Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate and N1.Inqty >0 and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription Union All select N1.Warehouse, N1.Itemcode, N1.Dscription, 0 as OpeningBalance, 0 , sum(N1.outqty) as OUT From dbo.OINM N1 Where N1.DocDate >= @FromDate and N1.DocDate <=@ToDate and N1.OutQty >0 and N1.Warehouse = @Whse Group By N1.Warehouse,N1.ItemCode,N1.Dscription) a, dbo.OITM I1 where a.ItemCode=I1.ItemCode Group By a.Itemcode Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0 Order By a.Itemcode

2.

Purchase-GRPO-Applied Amount-SQL query

SELECT --T6.PrjName, MAX(T2.DocNum) as ' PO NO', T2.DocEntry as ' PO NO Navigation', T2.DocDate as 'PoDATE', T2.CardName as 'Supplier Name', T0.Dscription as 'POItem', T0.Quantity as 'PoQty', T0.Price as 'POPrice', T0.LineTotal as 'POTot', MAX(T4.DocNum) as 'GRN No', T4.DocEntry as 'GRN No Navigation', T4.DocDate as 'GRN Date', T4.Numatcard as 'Supplier Reference No', T1.ItemCode as 'GRN Item', T1.Quantity as 'GRN Qty', T1.Price as 'GRN Price', T1.Currency as 'GRN Cur', MAX(T5.DocNum) as 'INV No', T5.DocEntry as 'INV No Navigation', T5.DocDate as 'INV Date', T5.Numatcard as 'Supplier Reference No', T3.Quantity as 'INV Qty', T3.Price as 'INV Price', T3.Currency as 'INV Cur', T3.LineTotal as 'INV Tot', T5.PaidtoDate as 'Paid Sum', (T3.LineTotal - T5.PaidtoDate) as 'Balance Due', --T7.CheckNum AS 'CheckNo', --T7.DueDate as 'CheckDate', --T7.CheckSum as 'CheckSum',

--T8.Cashsum as 'Cash Amount', T2.DocStatus AS ' PO Document Status' FROM POR1 T0 INNER JOIN PDN1 T1 ON T0.TrgetEntry = T1.DocEntry AND T0.Itemcode = T1.ItemCode AND T0.LineNum = T1.Baseline AND T0.DocEntry = T1.BaseEntry INNER JOIN OPOR T2 ON T0.DocEntry = T2.DocEntry INNER JOIN PCH1 T3 ON T1.TrgetEntry = T3.DocEntry AND T1.ItemCode = T3.ItemCode AND T1.LineNum = T3.Baseline AND T1.DocEntry = T3.BaseEntry INNER JOIN OPDN T4 ON T1.DocEntry = T4.DocEntry INNER JOIN OPCH T5 ON T3.DocEntry = T5.DocEntry left outer JOIN OPRJ T6 ON T2.PROJECT = T6.PRJCODE LEFT OUTER join VPM1 T7 on T7.DOCNUM = T5.RECEIPTNUM LEFT OUTER JOIN OVPM T8 on T8.DocEntry = T5.DepositNum WHERE T0.[DocDate] >='[%0]' and T0.[DocDate] <='[%1]' GROUP BY --T6.PrjName, T2.DocNum, T2.DocEntry, T2.DocDate, T2.CardName, T0.Dscription, T0.Quantity, T0.Price, T0.LineTotal,

3.Purchase Register Query:


SELECT M.DocNum AS 'AP Inv. #', M.DocDate as 'Date', M.CardName as 'Vendor Name', M.numatcard as'Vendor Ref No',M.Doccur as 'Currency', (Select Sum(LineTotal) FROM PCH1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)', (SELECT Sum(TaxSum) FROM PCH4 where statype=-90 and DocEntry=M.DocEntry) as 'BED (Rs.)', (SELECT Sum(TaxSum) FROM PCH4 where statype=-60 and DocEntry=M.DocEntry) as 'Cess (Rs.)', (SELECT Sum(TaxSum) FROM PCH4 where statype=-55 and DocEntry=M.DocEntry) as 'HECess (Rs.)', (SELECT Sum(TaxSum) FROM PCH4 where statype in ('1','10','11') and DocEntry=M.DocEntry) as ' VAT (Rs.) ', (SELECT Sum(TaxSum) FROM PCH4 where statype in ('4','12') and DocEntry=M.DocEntry) as ' CST (Rs.) ', (SELECT Sum(TaxSum) FROM PCH4 where statype=5 and DocEntry=M.DocEntry) as ' Ser.Tax (Rs.) ', (SELECT Sum(TaxSum) FROM PCH4 where statype=6 and DocEntry=M.DocEntry) as 'Cess_ST(Rs.)', (SELECT Sum(TaxSum) FROM PCH4 where statype=-10 and DocEntry=M.DocEntry) as 'HECess_ST(Rs.)', (Select Sum(LineTotal) From PCH3 Q Where Q.DocEntry=M.DocEntry) AS 'Freight (Rs.)', M.WTSum AS 'TDS (Rs.)',

M.DocTotal as 'Total (Rs.)' FROM OPCH M LEFT OUTER JOIN PCH1 L on L.DocEntry=M.DocEntry LEFT OUTER JOIN PCH4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum LEFT OUTER JOIN PCH5 J ON M.DocEntry = J.AbsEntry LEFT OUTER JOIN PCH3 Q ON M.DocEntry = Q.DocEntry WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]') AND L.TargetType<>'19' GROUP BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.Doccur,M.DiscSum,M.WTSum,M. DocTotal ORDER BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.Doccur,M.DiscSum,M.WTSum,M. DocTotal

4.Sales Register Query:


SELECT M.DocNum AS 'AR Inv. #', M.DocDate as 'Date', M.CardName as 'Customer Name', M.numatcard as'Vendor Ref No', (Select Sum(LineTotal) FROM inv1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)', (SELECT Sum(TaxSum) FROM inv4 where statype=-90 and DocEntry=M.DocEntry) as 'BED (Rs.)', (SELECT Sum(TaxSum) FROM inv4 where statype=-60 and DocEntry=M.DocEntry) as 'Cess (Rs.)', (SELECT Sum(TaxSum) FROM inv4 where statype=-55 and DocEntry=M.DocEntry) as 'HECess (Rs.)', (SELECT Sum(TaxSum) FROM inv4 where statype in ('1','10','11') and DocEntry=M.DocEntry) as ' VAT (Rs.) ', (SELECT Sum(TaxSum) FROM inv4 where statype in ('4','12') and DocEntry=M.DocEntry) as ' CST (Rs.) ', (SELECT Sum(TaxSum) FROM inv4 where statype=5 and DocEntry=M.DocEntry) as ' Ser.Tax (Rs.) ', (SELECT Sum(TaxSum) FROM inv4 where statype=6 and DocEntry=M.DocEntry) as 'Cess_ST(Rs.)', (SELECT Sum(TaxSum) FROM inv4 where statype=-10 and DocEntry=M.DocEntry) as 'HECess_ST(Rs.)', (Select Sum(LineTotal) From inv3 Q Where Q.DocEntry=M.DocEntry) AS 'Freight (Rs.)', M.WTSum AS 'TDS (Rs.)', M.DocTotal as 'Total (Rs.)' FROM OINV M LEFT OUTER JOIN inv1 L on L.DocEntry=M.DocEntry LEFT OUTER JOIN inv4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum LEFT OUTER JOIN inv5 J ON M.DocEntry = J.AbsEntry LEFT OUTER JOIN inv3 Q ON M.DocEntry = Q.DocEntry WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]') AND L.Targettype<>'14' GROUP BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,M.DocTotal ORDER BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,M.DocTotal

Anda mungkin juga menyukai