Aging Query with Project
Hi all
Is it possible to change the current BP Project to show INV1.Project instead?
USE [SBODemoSG]
GO
/****** Object: StoredProcedure [dbo].[ARAgingByCustomerNameLC] Script Date: 08/06/2014 14:03:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ARAgingByCustomerNameLC]
@DATETO DATETIME,
@CARDCODEFM NVARCHAR(15),
@CARDCODETO NVARCHAR(15),
@CARDNAMEFM NVARCHAR(15),
@CARDNAMETO NVARCHAR(15),
@SLPNAMEFM NVARCHAR(15),
@SLPNAMETO NVARCHAR(15)
AS
DECLARE @ISCREDIT NVARCHAR(2),
@ISDEDIT NVARCHAR(2)
SET @ISCREDIT = 'C'
SET @ISDEDIT = 'D'
EXEC [AF_ARAging] '20091231','0','ZZZZZZ'
--************ CUSTOMER AGING REPORT FROM SAP BY USING MS SQL Profiler ***********--
SELECT CUST.CARDCODE, CUST.CARDNAME, OSLP.SLPCODE, OSLP.SLPNAME, CUST.ADDID, CUST.CreditLine, CUST.Balance, CUST.[GroupNum], CUST.PYMNTGROUP, '1' AS SECTION,
Convert(varchar(12),@DATETO,101) AS AGINGDATE, CASE ISNULL(AR.FCCurrency,'') WHEN '' THEN 'SGD' ELSE AR.FCCurrency END AS DOCCUR,
CASE TRANSTYPE WHEN '13' THEN 'Inv'
WHEN '14' THEN 'CN'
WHEN '18' THEN 'AP Inv'
WHEN '19' THEN 'AP CN'
WHEN '30' THEN 'JE'
WHEN '46' THEN 'Pym'
WHEN '24' THEN 'Rcp'
ELSE TRANSTYPE END AS DOCTYPE,
CASE WHEN ISNULL(REF2,'') <> '' THEN REF2 ELSE BASEREF END AS DOCNUM, T0.Project,
REF2, Convert(varchar(12),REFDATE,101) AS REFDATE, Convert(varchar(12),DUEDATE,101) AS DUEDATE,
/* USE MONTH END RATE FOR AMOUNT IN SGD */
CASE ISNULL(RATE.RATE,0) WHEN 0 THEN AR.TOTAL * -1 ELSE RATE.RATE * AR.TOTALFC * -1 END AS DOCAMOUNT,
0 AS INVOICENO, 0 AS AMTAPPLIED,
CASE ISNULL(AR.FCCurrency,'') WHEN '' THEN 0 ELSE TOTALFC * -1 END AS DOCAMOUNTFC,
(SELECT MAX(COMPNYNAME) FROM OADM) AS COMPANYNAME,
RATE.RATE
--AR.* , CUST.*, DOC.NUMATCARD, ACT.* 3
FROM
SELECT T1.[TransId], T0.[Ref2],T1.[TransRowId], MAX(T0.[ShortName]) AS [ShortName], MAX(T0.[TransType]) AS [TransType], MAX(T0.[CreatedBy]) AS [CreatedBy], MAX(T0.[BaseRef]) AS [BaseRef],
MAX(T0.[SourceLine]) AS [SourceLine], MAX(T0.[RefDate]) AS [RefDate], MAX(T0.[DueDate]) AS [DueDate], MAX(T0.[TaxDate]) AS [TaxDate], MAX(T0.[BalDueCred]) + SUM(T1.[ReconSum]) AS TOTAL,
MAX(T0.[BalFcCred]) + SUM(T1.[ReconSumFC]) AS TOTALFC, MAX(T0.[BalScCred]) + SUM(T1.[ReconSumSC]) AS TOTALSC, MAX(T0.[LineMemo]) AS [LineMemo], MAX(T3.[FolioPref]) AS [FolioPref],
MAX(T3.[FolioNum]) AS [FolioNum], MAX(T0.[Indicator]) AS [Indicator], MAX(T0.[Account]) AS [Account],
MAX(T0.FCCurrency) as [FCCurrency]
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[ITR1] T1 ON T1.[TransId] = T0.[TransId] AND T1.[TransRowId] = T0.[Line_ID]
INNER JOIN [dbo].[OITR] T2 ON T2.[ReconNum] = T1.[ReconNum]
INNER JOIN [dbo].[OJDT] T3 ON T3.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C' AND T0.[RefDate] <= @DATETO AND T2.[ReconDate] > @DATETO AND T1.[IsCredit] = @ISCREDIT AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T1.[TransId],T0.[Ref2],T1.[TransRowId]
HAVING MAX(T0.[BalFcCred]) <>- SUM(T1.ReconSumFC) OR MAX(T0.[BalDueCred]) <>- SUM(T1.ReconSum)
UNION
SELECT T1.[TransId],T0.[Ref2],T1.[TransRowId],
MAX(T0.[ShortName]), MAX(T0.[TransType]), MAX(T0.[CreatedBy]), MAX(T0.[BaseRef]), MAX(T0.[SourceLine]), MAX(T0.[RefDate]), MAX(T0.[DueDate]), MAX(T0.[TaxDate]), - MAX(T0.[BalDueDeb]) - SUM(T1.[ReconSum]),
- MAX(T0.[BalFcDeb]) - SUM(T1.[ReconSumFC]), - MAX(T0.[BalScDeb]) - SUM(T1.[ReconSumSC]), MAX(T0.[LineMemo]), MAX(T3.[FolioPref]), MAX(T3.[FolioNum]), MAX(T0.[Indicator]), MAX(T0.[Account]) ,
MAX(T0.FCCurrency) as [FCCurrency]
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[ITR1] T1 ON T1.[TransId] = T0.[TransId] AND T1.[TransRowId] = T0.[Line_ID]
INNER JOIN [dbo].[OITR] T2 ON T2.[ReconNum] = T1.[ReconNum]
INNER JOIN [dbo].[OJDT] T3 ON T3.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C' AND T0.[RefDate] <= @DATETO AND T2.[ReconDate] > @DATETO AND T1.[IsCredit] = @ISDEDIT AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T1.[TransId],T0.[Ref2],T3.[Ref2],T1.[TransRowId] HAVING MAX(T0.[BalFcDeb]) <>- SUM(T1.ReconSumFC) OR MAX(T0.[BalDueDeb]) <>- SUM(T1.ReconSum)
UNION
SELECT T0.[TransId],T0.[Ref2],T0.[Line_ID], MAX(T0.[ShortName]), MAX(T0.[TransType]), MAX(T0.[CreatedBy]),
MAX(T0.[BaseRef]), MAX(T0.[SourceLine]), MAX(T0.[RefDate]), MAX(T0.[DueDate]), MAX(T0.[TaxDate]), MAX(T0.[BalDueCred]) - MAX(T0.[BalDueDeb]), MAX(T0.[BalFcCred]) - MAX(T0.[BalFcDeb]), MAX(T0.[BalScCred]) -
MAX(T0.[BalScDeb]), MAX(T0.[LineMemo]), MAX(T1.[FolioPref]), MAX(T1.[FolioNum]), MAX(T0.[Indicator]), MAX(T0.[Account]) ,
MAX(T0.FCCurrency) as [FCCurrency]
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[OJDT] T1 ON T1.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C' AND T0.[RefDate] <= @DATETO
AND NOT EXISTS
(SELECT U0.[TransId], U0.[TransRowId] FROM [dbo].[ITR1] U0 INNER JOIN [dbo].[OITR] U1 ON U0.[ReconNum] = U1.[ReconNum] WHERE T0.[TransId] = U0.[TransId]
AND T0.[Line_ID] = U0.[TransRowId] AND U1.[ReconDate] > @DATETO GROUP BY U0.[TransId], U0.[TransRowId]) AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T0.[TransId],T0.[Ref2], T0.[Line_ID]
HAVING MAX(T0.[BalFcCred]) <> MAX(T0.BalFcDeb) OR MAX(T0.[BalDueCred]) <> MAX(T0.BalDueDeb)
) AS AR
INNER JOIN
SELECT T0.CARDCODE, MAX(T0.CARDNAME) AS CARDNAME, MAX(T0.CURRENCY) AS CURRENCY, MAX(T3.PYMNTGROUP) AS PYMNTGROUP, MAX(T1.STREET) AS STREET,
MAX(T1.BLOCK) AS BLOCK, MAX(T1.CITY) AS CITY, MAX(T1.ZIPCODE) AS ZIPCODE, MAX(T1.COUNTY) AS COUNTY, MAX(T2.CNTCTCODE) AS CNTCTCODE,
MAX(T2.NAME) AS 'ContactPerson', MAX(T2.TEL1) AS TEL1, MAX(T2.FAX) AS FAX, MAX(T4.GroupName) AS BPGROUP, MAX(T0.SLPCODE) AS SLPCODE,
MAX(T0.ADDID) AS ADDID, MAX(T0.CreditLine) AS CreditLine, MAX(T0.[Balance]) AS [Balance], MAX(T0.[GroupNum]) AS [GroupNum]
FROM OCRD T0
LEFT OUTER JOIN CRD1 T1
ON T0.CARDCODE = T1.CARDCODE AND T0.BILLTODEF = T1.ADDRESS
LEFT OUTER JOIN OCPR T2
ON T0.CARDCODE = T2.CARDCODE AND T0.CNTCTPRSN = T2.NAME
LEFT OUTER JOIN OCTG T3
ON T0.GROUPNUM = T3.GROUPNUM
LEFT OUTER JOIN OCRG T4
ON T0.GroupCode = T4.GroupCode
WHERE T0.CARDTYPE = 'C' AND T0.CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T0.CARDCODE
) CUST
ON AR.[ShortName] = CUST.CARDCODE AND CUST.CARDNAME BETWEEN @CARDNAMEFM AND @CARDNAMETO
LEFT OUTER JOIN
( SELECT DOCNUM, OBJTYPE, NUMATCARD, T0.Project FROM OINV WHERE CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO
UNION
SELECT DOCNUM, OBJTYPE, NUMATCARD, T0.Project FROM ORIN WHERE CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO
) AS DOC
ON AR.BASEREF = DOC.DOCNUM AND AR.TRANSTYPE = DOC.OBJTYPE
LEFT OUTER JOIN
Select T0.ClgCode as 'ActNo', T0.CardCode, T0.EndDate as 'ActDate',
T0.EndTime as 'ActTime', T0.Details as 'Remarks'
From OCLG T0
INNER JOIN
(SELECT CardCode, MAX(EndDate) AS EndDate FROM OCLG WHERE ENDDATE < = @DATETO
GROUP BY CardCode HAVING MAX(EndDate) = MAX(EndDate)) T1
ON T0.CARDCODE = T1.CARDCODE AND T0.ENDDATE = T1.ENDDATE
) AS ACT
ON CUST.CARDCODE = ACT.CARDCODE
INNER JOIN
(SELECT * FROM OSLP) OSLP
ON CUST.SLPCODE = OSLP.SLPCODE
LEFT OUTER JOIN
(SELECT T0.F_REFDATE, T0.T_REFDATE, T1.CURRENCY, T1.RATE FROM OFPR T0 INNER JOIN ORTT T1 ON T0.T_REFDATE = T1.RATEDATE) RATE
ON AR.FCCurrency = RATE.CURRENCY AND AR.REFDATE BETWEEN RATE.F_REFDATE AND RATE.T_REFDATE
WHERE OSLP.SLPNAME BETWEEN @SLPNAMEFM AND @SLPNAMETO
ORDER BY CUST.CARDNAME, CUST.CARDCODE, convert(varchar(10),AR.REFDATE,112)
Highlighted below, is it working or not...
declare @DATETO DATETIME,
@CARDCODEFM NVARCHAR(15),
@CARDCODETO NVARCHAR(15),
@CARDNAMEFM NVARCHAR(15),
@CARDNAMETO NVARCHAR(15),
@SLPNAMEFM NVARCHAR(15),
@SLPNAMETO NVARCHAR(15)
DECLARE @ISCREDIT NVARCHAR(2),
@ISDEDIT NVARCHAR(2)
SET @ISCREDIT = 'C'
SET @ISDEDIT = 'D'
SELECT CUST.CARDCODE,
CUST.CARDNAME,
OSLP.SLPCODE,
OSLP.SLPNAME,
CUST.ADDID,
CUST.CreditLine,
CUST.Balance,
CUST.[GroupNum],
CUST.PYMNTGROUP,
'1' AS SECTION,
Convert(varchar(12),@DATETO,101) AS AGINGDATE,
CASE ISNULL(AR.FCCurrency,'')
WHEN '' THEN 'SGD'
ELSE AR.FCCurrency
END AS DOCCUR,
CASE TRANSTYPE
WHEN '13' THEN 'Inv'
WHEN '14' THEN 'CN'
WHEN '18' THEN 'AP Inv'
WHEN '19' THEN 'AP CN'
WHEN '30' THEN 'JE'
WHEN '46' THEN 'Pym'
WHEN '24' THEN 'Rcp'
ELSE TRANSTYPE
END AS DOCTYPE,
CASE
WHEN ISNULL(REF2,'') <> '' THEN REF2
ELSE BASEREF
END AS DOCNUM,
doc.Project,
REF2,
Convert(varchar(12),REFDATE,101) AS REFDATE,
Convert(varchar(12),DUEDATE,101) AS DUEDATE,
/* USE MONTH END RATE FOR AMOUNT IN SGD */
CASE ISNULL(RATE.RATE,0)
WHEN 0 THEN AR.TOTAL * -1
ELSE RATE.RATE * AR.TOTALFC * -1
END AS DOCAMOUNT,
0 AS INVOICENO,
0 AS AMTAPPLIED,
CASE ISNULL(AR.FCCurrency,'')
WHEN '' THEN 0
ELSE TOTALFC * -1
END AS DOCAMOUNTFC,
(SELECT MAX(COMPNYNAME)
FROM OADM) AS COMPANYNAME,
RATE.RATE --AR.* , CUST.*, DOC.NUMATCARD, ACT.* 3
FROM (
SELECT T1.[TransId], T0.[Ref2],T1.[TransRowId], MAX(T0.[ShortName]) AS [ShortName], MAX(T0.[TransType]) AS [TransType], MAX(T0.[CreatedBy]) AS [CreatedBy], MAX(T0.[BaseRef]) AS [BaseRef],
MAX(T0.[SourceLine]) AS [SourceLine], MAX(T0.[RefDate]) AS [RefDate], MAX(T0.[DueDate]) AS [DueDate], MAX(T0.[TaxDate]) AS [TaxDate], MAX(T0.[BalDueCred]) + SUM(T1.[ReconSum]) AS TOTAL,
MAX(T0.[BalFcCred]) + SUM(T1.[ReconSumFC]) AS TOTALFC, MAX(T0.[BalScCred]) + SUM(T1.[ReconSumSC]) AS TOTALSC, MAX(T0.[LineMemo]) AS [LineMemo], MAX(T3.[FolioPref]) AS [FolioPref],
MAX(T3.[FolioNum]) AS [FolioNum], MAX(T0.[Indicator]) AS [Indicator], MAX(T0.[Account]) AS [Account], MAX(T0.FCCurrency) AS [FCCurrency],t0.Project
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[ITR1] T1 ON T1.[TransId] = T0.[TransId] AND T1.[TransRowId] = T0.[Line_ID]
INNER JOIN [dbo].[OITR] T2 ON T2.[ReconNum] = T1.[ReconNum]
INNER JOIN [dbo].[OJDT] T3 ON T3.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C'
AND T0.[RefDate] <= @DATETO AND T2.[ReconDate] > @DATETO AND T1.[IsCredit] = @ISCREDIT AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T1.[TransId],T0.[Ref2],T1.[TransRowId],t0.Project HAVING MAX(T0.[BalFcCred]) <>- SUM(T1.ReconSumFC) OR MAX(T0.[BalDueCred]) <>- SUM(T1.ReconSum)
UNION
SELECT T1.[TransId],T0.[Ref2],T1.[TransRowId], MAX(T0.[ShortName]), MAX(T0.[TransType]),
MAX(T0.[CreatedBy]), MAX(T0.[BaseRef]), MAX(T0.[SourceLine]), MAX(T0.[RefDate]),
MAX(T0.[DueDate]), MAX(T0.[TaxDate]), - MAX(T0.[BalDueDeb]) - SUM(T1.[ReconSum]), - MAX(T0.[BalFcDeb])
- SUM(T1.[ReconSumFC]), - MAX(T0.[BalScDeb]) - SUM(T1.[ReconSumSC]), MAX(T0.[LineMemo]), MAX(T3.[FolioPref]),
MAX(T3.[FolioNum]), MAX(T0.[Indicator]), MAX(T0.[Account]) , MAX(T0.FCCurrency) AS [FCCurrency],t0.Project
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[ITR1] T1 ON T1.[TransId] = T0.[TransId] AND T1.[TransRowId] = T0.[Line_ID]
INNER JOIN [dbo].[OITR] T2 ON T2.[ReconNum] = T1.[ReconNum]
INNER JOIN [dbo].[OJDT] T3 ON T3.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C'
AND T0.[RefDate] <= @DATETO AND T2.[ReconDate] > @DATETO AND T1.[IsCredit] = @ISDEDIT AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T1.[TransId],T0.[Ref2],T3.[Ref2],T1.[TransRowId] ,t0.Project HAVING MAX(T0.[BalFcDeb]) <>- SUM(T1.ReconSumFC) OR MAX(T0.[BalDueDeb]) <>- SUM(T1.ReconSum)
UNION
SELECT T0.[TransId],T0.[Ref2],T0.[Line_ID], MAX(T0.[ShortName]), MAX(T0.[TransType]), MAX(T0.[CreatedBy]),
MAX(T0.[BaseRef]), MAX(T0.[SourceLine]), MAX(T0.[RefDate]), MAX(T0.[DueDate]), MAX(T0.[TaxDate]), MAX(T0.[BalDueCred]) - MAX(T0.[BalDueDeb]), MAX(T0.[BalFcCred]) - MAX(T0.[BalFcDeb]), MAX(T0.[BalScCred]) - MAX(T0.[BalScDeb]), MAX(T0.[LineMemo]), MAX(T1.[FolioPref]), MAX(T1.[FolioNum]), MAX(T0.[Indicator]), MAX(T0.[Account]) ,
MAX(T0.FCCurrency) AS [FCCurrency],t0.Project
FROM [dbo].[JDT1] T0 INNER JOIN [dbo].[OJDT] T1 ON T1.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OCRD] T4 ON T0.[ShortName] = T4.CARDCODE
WHERE T4.CARDTYPE = 'C'
AND T0.[RefDate] <= @DATETO
AND NOT EXISTS
(SELECT U0.[TransId], U0.[TransRowId] FROM [dbo].[ITR1] U0 INNER JOIN [dbo].[OITR] U1 ON U0.[ReconNum] = U1.[ReconNum] WHERE T0.[TransId] = U0.[TransId]
AND T0.[Line_ID] = U0.[TransRowId] AND U1.[ReconDate] > @DATETO GROUP BY U0.[TransId], U0.[TransRowId]) AND T0.[ShortName] BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T0.[TransId],T0.[Ref2], T0.[Line_ID],t0.Project HAVING MAX(T0.[BalFcCred]) <> MAX(T0.BalFcDeb) OR MAX(T0.[BalDueCred]) <> MAX(T0.BalDueDeb)) AS AR
INNER JOIN (
SELECT T0.CARDCODE,
MAX(T0.CARDNAME) AS CARDNAME,
MAX(T0.CURRENCY) AS CURRENCY,
MAX(T3.PYMNTGROUP) AS PYMNTGROUP,
MAX(T1.STREET) AS STREET,
MAX(T1.BLOCK) AS BLOCK,
MAX(T1.CITY) AS CITY,
MAX(T1.ZIPCODE) AS ZIPCODE,
MAX(T1.COUNTY) AS COUNTY,
MAX(T2.CNTCTCODE) AS CNTCTCODE,
MAX(T2.NAME) AS 'ContactPerson',
MAX(T2.TEL1) AS TEL1,
MAX(T2.FAX) AS FAX,
MAX(T4.GroupName) AS BPGROUP,
MAX(T0.SLPCODE) AS SLPCODE,
MAX(T0.ADDID) AS ADDID,
MAX(T0.CreditLine) AS CreditLine,
MAX(T0.[Balance]) AS [Balance], MAX(T0.[GroupNum]) AS [GroupNum]
FROM OCRD T0
LEFT OUTER JOIN CRD1 T1 ON T0.CARDCODE = T1.CARDCODE
AND T0.BILLTODEF = T1.ADDRESS
LEFT OUTER JOIN OCPR T2 ON T0.CARDCODE = T2.CARDCODE
AND T0.CNTCTPRSN = T2.NAME
LEFT OUTER JOIN OCTG T3 ON T0.GROUPNUM = T3.GROUPNUM
LEFT OUTER JOIN OCRG T4 ON T0.GroupCode = T4.GroupCode
WHERE T0.CARDTYPE = 'C'
AND T0.CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO
GROUP BY T0.CARDCODE) CUST ON AR.[ShortName] = CUST.CARDCODE
AND CUST.CARDNAME BETWEEN @CARDNAMEFM AND @CARDNAMETO
LEFT OUTER JOIN
(SELECT DOCNUM,
OBJTYPE,
NUMATCARD,Project
FROM OINV
WHERE CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO
UNION SELECT DOCNUM,
OBJTYPE,
NUMATCARD,Project
FROM ORIN
WHERE CARDCODE BETWEEN @CARDCODEFM AND @CARDCODETO) AS DOC ON AR.BASEREF = DOC.DOCNUM
AND AR.TRANSTYPE = DOC.OBJTYPE
LEFT OUTER JOIN
(SELECT T0.ClgCode AS 'ActNo',
T0.CardCode,
T0.EndDate AS 'ActDate',
T0.EndTime AS 'ActTime',
T0.Details AS 'Remarks'
FROM OCLG T0
INNER JOIN
(SELECT CardCode,
MAX(EndDate) AS EndDate
FROM OCLG
WHERE ENDDATE < = @DATETO
GROUP BY CardCode HAVING MAX(EndDate) = MAX(EndDate)) T1 ON T0.CARDCODE = T1.CARDCODE
AND T0.ENDDATE = T1.ENDDATE) AS ACT ON CUST.CARDCODE = ACT.CARDCODE
INNER JOIN
(SELECT *
FROM OSLP) OSLP ON CUST.SLPCODE = OSLP.SLPCODE
LEFT OUTER JOIN
(SELECT T0.F_REFDATE,
T0.T_REFDATE,
T1.CURRENCY,
T1.RATE
FROM OFPR T0
INNER JOIN ORTT T1 ON T0.T_REFDATE = T1.RATEDATE) RATE ON AR.FCCurrency = RATE.CURRENCY
AND AR.REFDATE BETWEEN RATE.F_REFDATE AND RATE.T_REFDATE WHERE OSLP.SLPNAME BETWEEN @SLPNAMEFM AND @SLPNAMETO
ORDER BY CUST.CARDNAME,
CUST.CARDCODE,
convert(varchar(10),AR.REFDATE,112)
Regards
Kennedy
Similar Messages
-
Stock Ageing Query With Stock Value
Dear Experts,
Greeting for the day...!
I am using Batch wise stock, so consumption done by batch wise.
Please forward me the query for the Product Code, Products Name, Batch No, Batch Qty (Under respective ageing days), Batch Amount (Under respective ageing days).
The parameter will be from date & to date & group.
Thanks in advance.
Regards
Datta KharatHi,
Please check this thread:
http://scn.sap.com/thread/3372541
Thanks & Regards,
Nagarajan -
Help with aging query. not sure how to acomplish this???
Guys im a bit stuck usually i have a slight idea how to even start my query but for this particular one I just dont even know where to start to tackle
i have a table like so.
create table TRRACCD (
TRRACCD_GRNT_CODE varchar2(6),
TRRACCD_TRANS_dATE date,
TRRACCD_AMOUNT number(17,2),
trraccd_detail_code varchar2(6))with data like so
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('15-FEB-10', 'DD-MM-RR'),19764.77,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('12-MAR-10', 'DD-MM-RR'),2054.29,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('20-APR-10', 'DD-MM-RR'),4111.46,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('14-MAY-10', 'DD-MM-RR'),2570.1,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-JUN-10', 'DD-MM-RR'),2176.16,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('12-JUL-10', 'DD-MM-RR'),4756.29,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('13-AUG-10', 'DD-MM-RR'),28500.62,'GCSH');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('16-AUG-10', 'DD-MM-RR'),3602.3,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('17-SEP-10', 'DD-MM-RR'),3995.79,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-OCT-10', 'DD-MM-RR'),3413.6,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-NOV-10', 'DD-MM-RR'),2119.86,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-DEC-10', 'DD-MM-RR'),5905.52,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-DEC-10', 'DD-MM-RR'),12008.21,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-JAN-11', 'DD-MM-RR'),-10574.05,'GBIL');
INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-JAN-11', 'DD-MM-RR'),20241.9,'GBIL');however what i need to do is end up with an aging for the items summarize so the expected output should be something like
tbrraccd_grnt_Code 30-60 60-90 over90
400364 20,241.90 2119.86 7,370.09
if your confused about how i arrived at the 7370.90 is because i have to subtract entries with GCSH on them and i also need to take
entries that are - and applied them to the oldest period if the balance of the period is positive. im inclined to say that i can do this with sql but the only other way i can think of is using plsql?... any suggestions or solutions would be greatly appreciated.
the closest that i have gotten to acomplishing this query without pl is this. i know is lame but i need help.
SELECT TRRACCD_GRNT_CODE,
TRRACCD_TRANS_dATE,
TRRACCD_AMOUNT,
trraccd_detail_code,
round(sysdate - TRRACCD_TRANS_dATE) "total days"
--sum(case when round(sysdate - TRRACCD_TRANS_dATE)>190 then "greater then 190"end )
FROM TRRACCD
where trraccd_grnt_Code = '400364'
ORDER BY TRRACCD_GRNT_CODE,
TRRACCD_TRANS_dATE,
trraccd_detail_code;Hi, Miguel,
I should have mentioned this before: I'm assuming SYSDATE is some point on January 22, 2011, after 00:00. I don't think this has caused any confusion so far, but if the discussion continues for a day or two, let's be clear about that.
I think I see what you want regarding the rows where trraccd+detailcode='GSCH'. If we completly ignored all the GSCH rows, we would get this output:
TRRACC 0-29 30-59 60-89 90-over
400364 ...
400404 19904.97 6625.27 4757.01 67618.68You want GSCH amounts to cancel other amounts in the last column only until that column reaches 0 ; the remaining GSCH amount will cancel amounts in to "60-89" column, again, only until that amount reaches 0 . If there is anything left over, it will cancel amounts in the "30-59" column, and if there is still some left over, the "0-29" column.
To be specific, trraccd_grnt_code=400404 has a total of 72475.69 from GSCH rows. That counts against the "90-over" total.
67618.68 - 72475.69 = -4757.01; you want to dispaly 0 in the "90-over" column, and apply the remaining 4757.01 to the next column to the left.
That column contains 4757.01, which happens to be the exact maount left over from the previous subtraction, so you want to diesplay 0 in the "60-89" column.
The remaining columns to the left should contain their regular totals.
Here's one way to do that:
WITH got_col_num AS
SELECT trraccd_grnt_code
, CASE
WHEN trraccd_detail_code != 'GCSH' THEN trraccd_amount
END AS net_amount
, SUM ( CASE
WHEN trraccd_detail_code = 'GCSH' THEN trraccd_amount
END
) OVER (PARTITION BY trraccd_grnt_code)
AS gsch_total
, CASE
WHEN trraccd_amount < 0 THEN 4
WHEN trraccd_trans_date > SYSDATE - 30 THEN 1
WHEN trraccd_trans_date > SYSDATE - 60 THEN 2
WHEN trraccd_trans_date > SYSDATE - 90 THEN 3
ELSE 4
END AS col_num
FROM trraccd
WHERE trraccd_trans_date <= SYSDATE
, got_sum AS
SELECT trraccd_grnt_code
, col_num
, LEAST ( SUM (net_amount)
, GREATEST ( 0
, SUM (SUM (net_amount)) OVER ( PARTITION BY trraccd_grnt_code
ORDER BY col_num DESC
- gsch_total
) AS total
FROM got_col_num
GROUP BY trraccd_grnt_code
, col_num
, gsch_total
SELECT trraccd_grnt_code
, SUM (CASE WHEN col_num = 1 THEN total END) AS "0-29"
, SUM (CASE WHEN col_num = 2 THEN total END) AS "30-59"
, SUM (CASE WHEN col_num = 3 THEN total END) AS "60-89"
, SUM (CASE WHEN col_num = 4 THEN total END) AS "90-over"
FROM got_sum
GROUP BY trraccd_grnt_code
ORDER BY trraccd_grnt_code
;Whenever you want to understand a query like this, run just the first sub-query (in this case, got_col_num) and make sure you understand what it's doing. When you do, add one more sub-query, and make sure you understand what it's doing.
Add morte columns to the display to help you understand it better. For example, when you get to the point where you're trying to understand the 2nd sub-query above, got_sum, you might run this query:
WITH got_col_num AS
SELECT trraccd_grnt_code
, CASE
WHEN trraccd_detail_code != 'GCSH' THEN trraccd_amount
END AS net_amount
, SUM ( CASE
WHEN trraccd_detail_code = 'GCSH' THEN trraccd_amount
END
) OVER (PARTITION BY trraccd_grnt_code)
AS gsch_total
, CASE
WHEN trraccd_amount < 0 THEN 4
WHEN trraccd_trans_date > SYSDATE - 30 THEN 1
WHEN trraccd_trans_date > SYSDATE - 60 THEN 2
WHEN trraccd_trans_date > SYSDATE - 90 THEN 3
ELSE 4
END AS col_num
FROM trraccd
WHERE trraccd_trans_date <= SYSDATE
, got_sum AS
SELECT trraccd_grnt_code
, col_num
, gsch_total
, SUM (net_amount) AS period_sum
, SUM (SUM (net_amount)) OVER ( PARTITION BY trraccd_grnt_code
ORDER BY col_num DESC
) AS running_sum
, LEAST ( SUM (net_amount)
, GREATEST ( 0
, SUM (SUM (net_amount)) OVER ( PARTITION BY trraccd_grnt_code
ORDER BY col_num DESC
- gsch_total
) AS total
FROM got_col_num
GROUP BY trraccd_grnt_code
, col_num
, gsch_total
SELECT *
FROM got_sum
ORDER BY trraccd_grnt_code
, col_num
;which produces this output:
TRRACC COL_NUM GSCH_TOTAL PERIOD_SUM RUNNING_SUM TOTAL
400364 1 28500.62 20241.9 76146.2 20241.9
400364 2 28500.62 17913.73 55904.3 17913.73
400364 3 28500.62 2119.86 37990.57 2119.86
400364 4 28500.62 35870.71 35870.71 7370.09
400404 1 72475.69 19904.97 99005.93 19904.97
400404 2 72475.69 6625.27 79100.96 6625.27
400404 3 72475.69 4857.01 72475.69 0
400404 4 72475.69 67618.68 67618.68 0The total column in that sub-query is very complicated, so break it down some. You can see that it is based on an analytic SUM whose argumenet is an aggregate SUM, all wrapped in LEAST and GREATEST. That can be very hard to underrstand, so break it down. Display the aggregate SUM by itself (period_sum) and also display the analytic SUM, without the GREATEST and LEAST.
mlov83 wrote:
where can i get more information about these types of querys?Can you be more specific? What types of queries do you mean? Complicated queries? Pivots? GROUP BY?
... I'm always leary of using a solution that i dont understand Excellent reaction!
would you mind expalining it to me a little.Again, could you be more specific? I don't mind explaining things to you, but I don't want to explain parts you already understand. If something is new, you'll want to read the SQL Language manual, or other sources, anyway, so it's more efficient to do that first, and then post specific questions on this forum.
An example of a more specific question is: "When I looked up "WITH clause" in the SQL Language reference, I found this page:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9758
but I don't understand where it says ...
The query above says ... Is that what the manual is talking about when it says ...?"
Another example of a good question is
"The query you posted says ... I don't understand what that's doing. I looked for ... and ... but that didn't seem to have anything to do with this query. What should I look for?
The Oracle 10 SQL Language manual is indexed pretty poorly. If you can't find something, it may not be your fault. -
Oracle 10g Diff in execution plan query with binding var Vs without
We recently did 10g upgrade. In 10g, execution plan differs for query with binding var(thru jdbc etc) Vs without it as given below. For query with binding var,
it chooses poor execution plan(no index is used, full scan is done etc). everything worked fine in 9i. To rectify the problem, we have to hint query with right index,join etc. but i dont like this solution.
I would rather prefer to correct database to choose right execution path instead of eacy query level. but not sure what causes the issue.
Does anybody came across this issue? if so, Please share your experiences. Thanks for the help. Do let me know if you need more info.
1. Query without binding bar:
select * from test where col1 = :1 and col2 = :2
1. Query without binding bar:
select * from test where col1 = 'foo' and col2= 'bar'I am not an expert but in my humble opinion it is the developer's responsability to ensure the correct explain plan is used before deploying code to production, if the explain plan returned by the DB is bad, then the use of a hint is perfectly acceptable.
Check this out: http://lcgapp.cern.ch/project/CondDB/snapshot/performance.html
Excerpt:
Bind variable peeking. If an SQL query contains bind variables, the optimal execution plan may depend on the values of those variables. When the Oracle query optimizer chooses the execution plan for such a query, it may indeed look at the values of all bind variables involved: this is known as "bind variable peeking".
In summary, the execution plan used for a given SQL query cannot be predicted a priori because it depends on the presence and quality of statistics and on the values of bind variables used at the time the query was first executed (hard-parsed). As a consequence of this instability of execution plans, very different performances may be observed for the same SQL query. In COOL, this issue is addressed by adding Oracle hints to the queries, to make sure that the same (good) plan is used in all cases, even with unreliable statistics or unfavourable bind variables.
Edited by: Rodolfo Ferrari on Jun 3, 2009 9:40 PM -
Query with aggregates over collection of trans. instances throws an error
Hi, I'm executing a query with aggregates an it throws an exception with the following message "Queries with aggregates or projections using variables currently cannot be executed in-memory. Either set the javax.jdo.option.IgnoreCache property to true, set IgnoreCache to true for this query,
set the kodo.FlushBeforeQueries property to true, or execute the query before changing any instances in the transaction.
The offending query was on type "class Pago" with filter "productosServicios.contains(item)".
The class Pago has the field productosServicios which is a List of Pago$ItemMonto, the relevant code is :
KodoQuery query = (KodoQuery)pm.newQuery(Pago.class,
pagos);
where pagos is a list of transient instances of type Pago.
query.declareVariables("Pago$ItemMonto item");
query.setFilter("productosServicios.contains(item)");
query.setGrouping("item.id");
query.setResult("item.id as idProductoServicio,
sum(montoTotal) as montoTotal");
query.setResultClass(PagoAgrupado.class);
where the class PagoAgrupado has the corresponding fields idProductoServicio and montoTotal.
In other words, I want to aggregate the id field of class ItemMonto over the instances contained in the productosServicios field of class Pago.
I have set to true the ignoreCache and kodo.FlushBeforeQueries flags in the kodo.properties file and in the instances of the pm and the query but it has not worked, what can be wrong?.
I'm using Kodo 3.2.4, MySQL 5.0
Thanks,
Jaime.
Message was edited by:
jdelajarafThanks, you nailed it! I tried comparing the two files myself, but Bridge told me that the 72.009 dpi document was 72 dpi.
I have no idea why the resolution mess things up, but as long as I know how to avoid the bug, things are grand! -
Hi Experts,
I have a client who needs a AR Aging query that only shows totals (not individual BP balances) for 30, 60, 90, 120 and over 120 days.
I can get the total with this query, but do now know how to go about the 30,60....
SELECT SUM(T0.BalanceSys) AS 'Total AR'
FROM OCRD T0
WHERE T0.CardType = 'C'
Any help would be appreciated.
MarliGordon,
Thanks so much for this help.
I have tested this in a Demo database and found that this results is not the same as the Aging report. Then I tested it in another database where I do not have as many transactions and still this was not the same.
I started to take only parts of the query and run them seperately. In this database I have only $80,954.85 due in the >120 days aging. Nothing else. Here is what this part of the query brought back: $425,929.06
SELECT SUM(T2.SYSDeb- T2.SYSCred)
FROM dbo.OCRD T0 INNER JOIN dbo.JDT1 T2 ON T2.ShortName = T0.CardCode
WHERE T2.[Account] = '_SYS00000000010'
AND T0.CardType = 'C' AND DateDiff(DD,T2.Duedate,GetDate()) >120
When I delete the DateDiff part I get the right total: $80,954.85
SELECT SUM(T2.SYSDeb- T2.SYSCred)
FROM dbo.OCRD T0 INNER JOIN dbo.JDT1 T2 ON T2.ShortName = T0.CardCode
WHERE T2.[Account] = '_SYS00000000010'
AND T0.CardType = 'C'
Thanks for your help,
Marli -
Filter query with sub query using Dropdown box
Dear Community,
I have 2 queries
1. Main Query with 2 fields: Project | Project value
2. Sub Query with 2 fields: Project group | Project
Project group can be belonging to number of projects and project can be belong to number of project group (Many to Many).
My customer wants the main query will open without any filtering.
When I choose project group from WAD dropdown box, the main query will filtering all the projects that belong to the project group.
I create WAD; define dropdown box as sub query, and Analysis as main query.
In the dropdown box I choose "data binding" char and create command "set selection state by binding" (project to project) but it doesnu2019t work.
I also try to do this by Replacement Path in the main query, but the variable requires the attribute will be ready for input.
Thanks a lot
YanivI am not sure about your comments on replacement path variable. Without having tried it, here is what I would have attempted:
The main query needs to use a replacement path variable for Project that is replaced by the results of the sub-query. Sub-query would have a regular input variable for project group. (as a quick test, if you had one analysis item for main query with variable input enabled, it should prompt you to enter Project group).
Now the drop-down needs to be associated with a javascript function. The javascript function needs to implement command "Set variable state" for the main query data provider to selected value of the drop-down.
The drop-down should be associated with the sub-query data provider, just used to populate the list of values in drop-down. -
What is aging report or aging query
hi
i am suresh,
what is aging report or aging query.
can any one tell.Hello Suresh,
Based on the business requirements you design the inventory aging report. Here are few scenarios:
1) Technical Name: 0IC_C03_Q0021
Use
This query displays the inventory aging for selected materials per week and calendar year, and is used in the KPI monitor.
2) Technical Name: 0IC_C01_Q0009
Use
The percentage of total gross inventory (based on value) covered by expected demand within a specific time bucket.
3)
With this picking strategy the system proposes the oldest quant in the storage type as the quant that should be transferred.
The system generally calculates the "age" (length of time in storage) of a quant on the basis of the goods receipt posting date from the Inventory Management (IM) application component. The system automatically sets the goods receipt date in the quant and in the transfer requirement for every goods receipt posting in IM. When the transfer order is created, this date is copied over to the quant record of the destination storage bin.
You can accept the goods receipt date that the system sets or you can enter a different date. Regardless of whether the system proposes the goods receipt date or you enter a different date, the date is used to calculate the age of the quant. This date influences the sorting sequence for each material.
Prerequisites
When you define the storage type record to use this strategy, enter f in the Picking strategy field.
you can find more details in Help.sap.com which fields needs to used etc.
Hope this helps,
Bye,
Naga.
Message was edited by: Naga Timmaraju -
Parametrized query with output from sql
Hey all,
has anyone figure out how to use the database connectivity toolset to perform a parameterized query with outputs (SQL)? From the other threads that i have read it would seem that this issue is not resolved. The error i get is:
Error -2147467259 occurred at Cmd Execute.vi->getjobID.vi
Possible reason(s):
Exception occured in Microsoft OLE DB Provider for ODBC Drivers: [MySQL][ODBC 3.51 Driver][mysqld-5.0.50sp1a-enterprise-gpl-log]OUT or INOUT argument 3 for routine eln.lv_caperJob_create is not a variable or NEW pseudo-variable in BEFORE trigger in Rec Create - Command.vi->Cmd Execute.vi->getjobID.vi
However, In Toad for mysql the following call works:
set @outJobID=-999;
set @outMsg="";
call lv_caperJob_create('TestJune30_2', '207', @outJobID, @outMsg);
select @outJobID, @outMsg
Attached is the LV code i am using. Thanks!
Attachments:
db code.JPG 50 KBYour first approach gave you an error because it took the ? parameter inside the '%?%' string and treated it as whole string as '%?%'. As you set the parameter, it did not understood where it need to insert the parameter.
Your second approach is pretty much OK, only problem is you are trying to set the parameter with a string and aging creating the string while setting the parameter.
The solution will be to create the whole string before setting the parameter and set the created String as parameter on the query something like this.
String parameter = "%"+searchString+"%";
Then set the parameter string to the query.
Thanks -
Rest query with filter sub-string (contains, not eq)
Hi,
how can I do a REST-query with a filter for a string-column which is only a sub-string? I only found EQ, for example $filter=(name EQ 'tom') which compares the whole string.
But I would like to query records, where a string-column CONTAINS a specific sub-string.
Thx, TomHi Tom,
Do you use it on azure Data Market place? Did you try to add "*" on your query string, like this
post.
Also, you could try this tool from this
thread. Also, for this issue, I suggest you could post it on
SQL forum for better support.
If I misunderstood, please let me know.
Regards,
Will
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Dear All
When i run the following GRPO query (with freight) it shows me 2 lines when there is multiple freight lines in the freight screen. Can anybody guide where the changes is to be made in this query.
SELECT T0.[DocNum] as 'GRPO Number',T0.[DocDate] as 'GRPO Date', t0.DocDueDate as 'Inspected Date',T0.[CardName] as 'Vendor Name', T0.[Project] as 'JOB Number', T0.U_PRNo as 'PRS Number',T0.U_BILL as 'Bill Number',T0.U_DC as 'DC Number',t0.u_doc_ref as 'Document Reference 1',T1.[BaseRef] as 'PO Number',sum (t1.linetotal) as 'Basic', T2.LineTotal AS 'Freight & P&F',
SUM(T3.TAXSUM) AS 'BEDAmt',
sum(t4.taxsum) as 'ECessAmt',
sum(t5.taxsum) as 'HECess Amt',
sum(t6.taxsum) as 'BED on Freight',
sum(t7.taxsum) as 'CESS on Freight',
sum(t8.taxsum) as 'HECess on Freight',
sum(t9.taxsum) as 'VAT ON Freight Amt',
sum(t10.taxsum) as 'CST ON Freight Amt',
sum(t11.taxsum) as 'VAT Amt',
sum(t12.taxsum) as 'VAT along with Excise Amt',
sum(t13.taxsum) as 'CST Amt',
sum(t14.taxsum) as 'CST along with Excise Amt',
sum(t15.taxsum) as 'AED Amt',
T0.Doctotal as 'Total Amount of GRPO'
FROM OPDN T0 INNER JOIN PDN1 T1 ON T0.DocEntry = T1.DocEntry
LEFT OUTER JOIN PDN3 T2 ON T2.DocEntry = T1.DocEntry
LEFT OUTER JOIN PDN4 T3 ON T3.DocEntry=T0.DocEntry and T0.DocEntry=T3.DocEntry AND T3.staType=-90 AND T1.LineNum=T3.LineNum
LEFT OUTER JOIN PDN4 T4 ON T4.DocEntry=T0.DocEntry and T0.DocEntry=T4.DocEntry AND T4.staType=-60 AND T1.LineNum=T4.LineNum
LEFT OUTER JOIN PDN4 T5 ON T5.DocEntry=T0.DocEntry and T0.DocEntry=T5.DocEntry AND T5.staType=7 AND T1.LineNum=T5.LineNum
LEFT OUTER JOIN PDN4 T6 ON T6.DocEntry=T0.DocEntry and T0.DocEntry=T6.DocEntry AND T6.staType=22 AND T1.LineNum=T6.LineNum
LEFT OUTER JOIN PDN4 T7 ON T7.DocEntry=T0.DocEntry and T0.DocEntry=T7.DocEntry AND T7.staType=23 AND T1.LineNum=T7.LineNum
LEFT OUTER JOIN PDN4 T8 ON T8.DocEntry=T0.DocEntry and T0.DocEntry=T8.DocEntry AND T8.staType=24 AND T1.LineNum=T8.LineNum
LEFT OUTER JOIN PDN4 T9 ON T9.DocEntry=T0.DocEntry and T0.DocEntry=T9.DocEntry AND T9.staType=25 AND T1.LineNum=T9.LineNum
LEFT OUTER JOIN PDN4 T10 ON T10.DocEntry=T0.DocEntry and T0.DocEntry=T10.DocEntry AND T10.staType=26 AND T1.LineNum=T10.LineNum
LEFT OUTER JOIN PDN4 T11 ON T11.DocEntry=T0.DocEntry and T0.DocEntry=T11.DocEntry AND T11.staType=1 AND T1.LineNum=T11.LineNum
LEFT OUTER JOIN PDN4 T12 ON T12.DocEntry=T0.DocEntry and T0.DocEntry=T12.DocEntry AND T12.staType=14 AND T1.LineNum=T12.LineNum
LEFT OUTER JOIN PDN4 T13 ON T13.DocEntry=T0.DocEntry and T0.DocEntry=T13.DocEntry AND T13.staType=4 AND T1.LineNum=T13.LineNum
LEFT OUTER JOIN PDN4 T14 ON T14.DocEntry=T0.DocEntry and T0.DocEntry=T14.DocEntry AND T14.staType=13 AND T1.LineNum=T14.LineNum
LEFT OUTER JOIN PDN4 T15 ON T15.DocEntry=T0.DocEntry and T0.DocEntry=T15.DocEntry AND T15.staType=-80 AND T1.LineNum=T15.LineNum
WHERE T0.[Project] between '[%0]' and '[%1]' or T0.[DocDate] between '[%2]' and '[%3]'
GROUP BY T0.[DocDate], T0.[DocNum],T0.[CardName], T0.[Project], T1.[BaseRef], T2.[LineTotal],T0.U_PRNo,t0.DocDueDate,T0.U_BILL,T0.U_DC,t0.U_DOC_REF,T0.Doctotal
REGARDS
KARTHIKHello Karthik,
Try This
declare @todate as datetime
declare @enddate as datetime
SELECT @todate= /*min(T0.DocDate) FROM OINM T0 WHERE T0.DocDate=*/ '[%0]'
SELECT @enddate= /*max(T0.DocDate) FROM OINM T0 WHERE T0.DocDate=*/'[%1]'
select DISTINCT a.Docnum as "GRPO No" ,a.docdate AS "GRPO Date" ,
a.cardname as "Supplier Name" ,a.DocDueDate ,
(select sum(LineTotal) from PDN1 where docentry = a.docentry)as "Basic Value" ,
(select sum(LineTotal) from PDN3 where docentry = a.docentry)as "Freight & P&F Am" ,a.DiscSum as 'Discount',
(Select sum(taxsum) FROM PDN4 where docentry = a.docentry and statype=-90) as "BED" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=-60) as "Cess" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=7) as "HeCess" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=-80) as "AED" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=13) as "CST along with Excise Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=4) as "CST" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=1) as "VAT" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=14) as "VAT along with Excise Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=26) as "CST on Freight Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=25) as "VAT on Freight Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=22) as "BED on Freight Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=23) as "CESS on Freight Amt" ,
(Select SUM(taxsum) FROM PDN4 where docentry = a.docentry and statype=24) as "HECESS on Freight Amt" ,
A.DocTotal as "Net Value"
FROM OPDN A left OUTER JOIN PDN3 B ON A.DOCENTRY = B.DOCENTRY left OUTER JOIN PDN4 C
ON A.DOCENTRY = C.DOCENTRY left outer join PDN3 h on A.DocEntry = h.DocEntry left outer join
PDN1 d on a.docentry = d.docentry left outer join crd7 e on a.cardcode = e.cardcode Left Outer Join
oitm g On d.ItemCode=g.ItemCode left outer join ochp f on f.absentry= g.chapterid where a.Docdate >=@todate
and a.Docdate <=@enddate and g.itemcode=d.itemcode ORDER BY A.DOCNUM
Regards:
Balaji.S -
Query with 'different from' clause in Sqlite
My question is very simple:
How can I submit a query with a 'different from' clause into a table.
In AIR, I would like to query :
"select * from myTable where myField <> 'value' ";
but it does'nt work !
Nor
"select * from myTable where myField != 'value' ";
nor
"select * from myTable where myField is not 'value' ";
is it impossible to query with a 'different from' clause in Sqlite wih Adobe AirHello,
SQLite in AIR does support 'different from' and '<>' is the correct operator. Take the following emp table for example:
id
name
age
1
A
26
2
B
30
3
C
28
If you want to query the records whose name isn't A. The following SQL is correct:
select * from emp where name <> 'A'
Thanks,
Yang -
How to create ageing query?
Hi Folks,
Could you give me an idea how to create an AGEING query by below requirement ?
Purpose is to calculate the Ageing, which can be defined as the difference between the Document Date and the current date.
As the current date is not practical (the AR gets updated once a month, and financial ageing reports usually report compared with end-of-the-month), I propose the
u2018Last working day of previous month.
When this interval is created per document the total revenue should be divided into columns based on the ageing:
1-30 days
31-60 days
61-90 days
91-120 days
121-360 days
>360 days.
Reporting Fields are :
Rows & Columns
Company code
SAP ID
Customer name
Country
City
Address
Postal code
Total AR
Current
1-30
31-60
61-90
91-120
>120
>360
Appreciate your response on this. Thanks : SurendraHi,
In this you follow th ebelow steps easy
Go To Create CK F menu-----
Craete one Formual Variable on Document Date with replacement path as 0document posted date
one more variable Formula Variable with customer exit on cal cal day
for that getting the current date write below code
WHEN 'ZCDATE'.
CLEAR: L_S_RANGE.
L_S_RANGE-LOW = SY-DATUM.
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'EQ'.
APPENDL_S_RANGETO E_T_RANGE.
ENDCASE.
when you are creating varaible there is tab in that ( last tab) currency/unit here you should mention date.
now use these two formula varaibles Current date formula variable- document date formula varaible
now uare getting the days
based on your requirement
use that
same Ckf
one ckf cuurent datevariable -posting datevariable >30( it gives 0-30)
in next Ckf current adte - posting date >30<60
like that you can create as you like.
Thansk & Regarsd,
sathish -
How can I change the age associated with my daughter's account?
OK I am sure that this is a common issue. Back when my daughter was about 9 or 10 years old, we bought her an iPod Touch. She was too young to have an AppleID of her own, so I set one up for her using an extra gmail accoun that I had, and entered my birthdate/age. A few years later, she received an iPad, and most recently, an iPhone. All of these devices are tied to the same AppleID.
Well, now she will be 13 years old soon, and I would like to switch things to represent reality. She has her own email account, and I believe you can go to My Apple Id to change the Apple ID name and e-mail address. My question is, can we change the age associated with the account?
I hear you saying, "Just create a new AppleID for her." That may end up being the only solution, but I am trying to avoid having two AppleIDs for her to keep up with. She has already purchased a fair amount of content (music and apps) under the existing AppleID, and I am pretty sure from looking at the posts on this Community that you can not transfer content away from the AppleID under which it was downloaded/purchased. And so, if I create a new AppleID, she will have to re-purchase the content to get it all in one place. As she eventually grows up and becomes independent, I would like for he to not have to "start over" with her AppleID.
Any advice or direction to information would be appreciated.I have a similar situation however a bit more complicated! It seems that when I was setting the birthdate I forgot to change the year so now my seven years old daughter shows up as a two months old! There is no way to change the birthdate because it shows up in light grey when I login into my daughters account and doesn't allow a change! The birthdate can be changed only when the child turns 13 however according to this she will have to be 20 before she can change it to show property 13 and here is where this is getting completely out of hand! Now to make things more complicated I have twin daughters and they came up with their unique but similar Apple ID, so changing one will require to change both Apple IDs! After being on the phone with Apple's customer support for about one hour I talked to a supervisor and the supervisor of the supervisor and their only solution is to create a new Apple ID! Of course in my case I will have to create two new Apple IDs, and I'm considering doing it. However when I started reading it becomes more complicated because I already made their Apple IDs part of my family group. It seems like you're not able to just let go of family member that is less than 13 years of age. You can only transfer it to another family, so Apple is making sure there are no kids left behind It seems like the only option will be to "abandon" the family and then create a new family with the new Apple IDs. If all this sounds bizarre to you it sounds bizarre to me too! If I can just put the kids in the car and drive them to the nearest one hour away Apple Store and have them show their credentials confirming their birthdate I would rather do that than having to spend more and more time with this issue, but that was not an option pointed out by customer support. So folks keep in mind that if you make a mistake your children's age is set in stone until he or she turns 20 if they happen to be seven at the time you made the mistake and no one can change this, even Apple! Now on the positive side I'm glad I didn't do the mistake when she was 13 or she will have to wait until she's 26 Most likely I'll be calling customer support tomorrow again and I will let you know how it went!
-
How to create an ABAP Query with OR logical expression in the select-where
Hi,
In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
Please help me on this.. Points will be rewarded.
Thanks a lot.
Regards,
Question ManHi Bhupal, Shanthi, and Saipriya,
Thanks for your replies. But that didn't answer my question.
Bhupal,
You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
Shanthi,
Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
Saipriya,
Like what I have said, this is a standard SAP code so we can't do your suggestion.
I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
Thanks a lot.
Points will be rewarded.
Regards,
Question Man
Maybe you are looking for
-
IOS devices not recognized in iTunes via USB
I am on a Windows 7 x64 home-built computer and I am pretty technically inclined, but this one problem has been bugging me for quite a while now. I am pleased that Apple wants its devices to sync wirelessly with iTunes from now on, but there are time
-
HELP!! Updated iTunes and now it won't work
I just updated itunes & quicktime. I can't open itunes, it tells me that I need to have quicktime 7.0.3. which I do. It tells me to reinstall which I've done 3 times. Help!!! Thank you!
-
HI, After delete the sales order how I can check the details of sales order & material & who deleted the sales order.Please give me the solution for this. Thanks, Rajesh..
-
Problem while installing Weblogic Server 10.0.3.2
Hi, I have downloaded wls1031_generic.jar & getting fatal error while installing the same.
-
How to identity segment when to setup partition for large table?
I have a table with size is about 3G. There is a code column in this table with distinguish 20 value. I am try to create list partition on this column. How can I assign segment for different value for this partition?In my database, only less than 10