Aging Report SQL Query

Dear Guys,
I have tried for aging report query , but still my expected results is not come. Please go through below the table and script data for your reference. Please wirte a query for aging report.
USE [SAMPLES]
GO
/****** Object: Table [dbo].[NEW_DCB_REPORT] Script Date: 02/12/2015 01:19:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[NEW_DCB_REPORT](
[MFDB_LedgerNumber] [int] IDENTITY(1,1) NOT NULL,
[MFDB_TxnDate] [datetime] NOT NULL,
[MFDB_StateId] [int] NOT NULL,
[MFDB_RegionId] [int] NOT NULL,
[MFDB_BranchId] [int] NOT NULL,
[MFDB_SHGId] [int] NOT NULL,
[MFDB_SHGName] [varchar](75) NOT NULL,
[MFDB_ShgMemberId] [int] NOT NULL,
[MFDB_MemberName] [varchar](50) NOT NULL,
[MFDB_VillageId] [int] NOT NULL,
[MFDB_LoanNumber] [int] NOT NULL,
[MFDB_LoanAmount] [int] NOT NULL,
[MFDB_DisbursedDate] [datetime] NOT NULL,
[MFDB_DemandDate] [datetime] NULL,
[MFDB_CollectionDate] [datetime] NULL,
[MFDB_InstallmentNumber] [int] NOT NULL,
[MFDB_ArrearPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_ArrearInterest] [numeric](18, 2) NOT NULL,
[MFDB_DemandPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_DemandInterest] [numeric](18, 2) NOT NULL,
[MFDB_TotDemandPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_TotDemandInterest] [numeric](18, 2) NOT NULL,
[MFDB_AdvOBPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_AdvOBInterest] [numeric](18, 2) NOT NULL,
[MFDB_CollectedPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_CollectedInterest] [numeric](18, 2) NOT NULL,
[MFDB_AdvCBPrincipal] [numeric](18, 2) NOT NULL,
[MFDB_AdvCBInterest] [numeric](18, 2) NOT NULL,
[MFDB_BalancePrincipal] [numeric](18, 2) NOT NULL,
[MFDB_BalanceInterest] [numeric](18, 2) NOT NULL,
[MFDB_OS_Pri] [numeric](18, 2) NOT NULL,
[MFDB_OS_Int] [numeric](18, 2) NOT NULL,
[MFDB_RepaymentPercentage] [int] NOT NULL,
[MFDB_LoanSchemeId] [int] NOT NULL,
[MFDB_LActivityId] [int] NOT NULL,
[MFDB_LActSpecId] [int] NOT NULL,
[MFDB_FundAgencyId] [int] NOT NULL,
[MFDB_LSourceId] [int] NOT NULL,
[MFDB_Months] [varchar](15) NOT NULL,
[MFDB_PanchayatId] [int] NOT NULL,
[MFDB_PanchayatName] [varchar](100) NOT NULL,
[MFDB_VillageName] [varchar](100) NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [SAMPLES];
SET NOCOUNT ON;
SET XACT_ABORT ON;
GO
SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] ON;
BEGIN TRANSACTION;
INSERT INTO [dbo].[NEW_DCB_REPORT]([MFDB_LedgerNumber], [MFDB_TxnDate], [MFDB_StateId], [MFDB_RegionId], [MFDB_BranchId], [MFDB_SHGId], [MFDB_SHGName], [MFDB_ShgMemberId], [MFDB_MemberName], [MFDB_VillageId], [MFDB_LoanNumber], [MFDB_LoanAmount], [MFDB_DisbursedDate], [MFDB_DemandDate], [MFDB_CollectionDate], [MFDB_InstallmentNumber], [MFDB_ArrearPrincipal], [MFDB_ArrearInterest], [MFDB_DemandPrincipal], [MFDB_DemandInterest], [MFDB_TotDemandPrincipal], [MFDB_TotDemandInterest], [MFDB_AdvOBPrincipal], [MFDB_AdvOBInterest], [MFDB_CollectedPrincipal], [MFDB_CollectedInterest], [MFDB_AdvCBPrincipal], [MFDB_AdvCBInterest], [MFDB_BalancePrincipal], [MFDB_BalanceInterest], [MFDB_OS_Pri], [MFDB_OS_Int], [MFDB_RepaymentPercentage], [MFDB_LoanSchemeId], [MFDB_LActivityId], [MFDB_LActSpecId], [MFDB_FundAgencyId], [MFDB_LSourceId], [MFDB_Months], [MFDB_PanchayatId], [MFDB_PanchayatName], [MFDB_VillageName])
SELECT 18, '20140422 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, NULL, 0, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Apr - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 162, '20140521 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140521 00:00:00.000', NULL, 1, 0.00, 0.00, 0.00, 150.00, 0.00, 150.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 150.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'May - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 13932, '20140621 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140621 00:00:00.000', NULL, 2, 0.00, 150.00, 909.00, 150.00, 909.00, 300.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 909.00, 300.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jun - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 32505, '20140721 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140721 00:00:00.000', NULL, 3, 909.00, 300.00, 909.00, 136.00, 1818.00, 436.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1818.00, 436.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jul - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 62524, '20140821 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140821 00:00:00.000', NULL, 4, 1818.00, 436.00, 909.00, 123.00, 2727.00, 559.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2727.00, 559.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Aug - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 100871, '20140921 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140921 00:00:00.000', NULL, 5, 2727.00, 559.00, 909.00, 109.00, 3636.00, 668.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3636.00, 668.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Sep - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 153679, '20141021 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141021 00:00:00.000', NULL, 6, 3636.00, 668.00, 909.00, 96.00, 4545.00, 764.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4545.00, 764.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Oct - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 203840, '20141119 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, '20141119 00:00:00.000', 2, 4545.00, 764.00, 0.00, 0.00, 4545.00, 764.00, 0.00, 0.00, 10000.00, 150.00, 5455.00, 0.00, 0.00, 614.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Nov - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 291259, '20141221 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141221 00:00:00.000', NULL, 8, 0.00, 614.00, 909.00, 68.00, 909.00, 682.00, 5455.00, 0.00, 0.00, 0.00, 4546.00, 0.00, 0.00, 682.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Dec - 14', 2927, N'PALI', N'PALI' UNION ALL
SELECT 363176, '20150121 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20150121 00:00:00.000', NULL, 9, 0.00, 682.00, 909.00, 55.00, 909.00, 737.00, 4546.00, 0.00, 0.00, 0.00, 3637.00, 0.00, 0.00, 737.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Jan - 15', 2927, N'PALI', N'PALI'
COMMIT;
RAISERROR (N'[dbo].[NEW_DCB_REPORT]: Insert Batch: 1.....Done!', 10, 1) WITH NOWAIT;
GO
SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] OFF;
I expected results as below:
Report As On Date: 30-10-2014
S.No. SHG NAME MEMBER NAME <=30 31-60 61-90 91-120 91-180 181-365 365 - 689 Above 2 Yrs
1 MAHALAXMI-5514 SUNITA 0 909 1818 2727 3636 4545 0 0
Report As On Date:
30-10-2014
S.No.
SHG NAME
MEMBER NAME
<=30
31-60
61-90
91-120
91-180
181-365
365 - 689
Above 2 Yrs
1
MAHALAXMI-5514
SUNITA
0
909
1818
2727
3636
4545
0
0

Thanks for your replay,  I have checked your query it seems nearly ok, Please find my script which i tried above for the same.
DECLARE @i_AsOnDate AS DATETIME = '2014-09-30'
;WITH CA1 AS
SELECT ROW_NUMBER() OVER(Order  By DR.MFDB_SHGName,DR.MFDB_MemberName)
AS SerialNumber,
  DR.MFDB_SHGId
AS ShgId,
  DR.MFDB_SHGName
AS ShgName,
  DR.MFDB_ShgMemberId
AS MemId,
  DR.MFDB_MemberName
AS MemName,
  ISNULL((SELECT CAST(SUM(LD.MFDB_StdPrincipal) AS BIGINT )
  FROM  MFDB_LOAN_DISBURSEMENT LD
  WHERE LD.MFDB_SHGId
= DR.MFDB_SHGId 
  AND   LD.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId 
  AND   LD.MFDB_LoanNumber
= DR.MFDB_LoanNumber
  AND   LD.MFDB_ApprovalStatus = 1
  AND   DATEDIFF(DAY,@i_AsOnDate,LD.MFDB_CollectionDate) > 0 ),0)
AS YETDUE,
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) >= 0
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 30
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '0-30',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 60 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 30
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '31-60',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 90 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 60
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '61-90',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 120 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 90
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '91-120',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 180 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 120
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '121-180',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 365 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 180
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '181-365',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 689 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 365
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS '366-689',
ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
FROM dbo.MFDB_NEW_DCB_REPORT ND
WHERE ND.MFDB_SHGId
= DR.MFDB_SHGId 
AND   ND.MFDB_ShgMemberId
= DR.MFDB_ShgMemberId  
AND   ND.MFDB_LoanNumber
= DR.MFDB_LoanNumber
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 730 
AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 689
ORDER BY ND.MFDB_LedgerNumber DESC),0)
AS 'Above_2_Yrs'   
FROM DBO.MFDB_NEW_DCB_REPORT DR
WHERE DR.MFDB_BranchId
= 67
AND   DR.MFDB_SHGId
IN (5514)
AND   DR.MFDB_ShgMemberId = 66735
AND   DATEDIFF(DAY,MFDB_TxnDate,@i_AsOnDate) >= 0  
SELECT * FROM CA1
results after the execution of the script:
SerialNumber
ShgId
ShgName
MemId
MemName
YETDUE
0-30
31-60
61-90
91-120
121-180
181-365
366-689
Above_2_Yrs
3
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
2
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
6
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
4
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
1
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
5
5514
MAHALAXMI-5514
SUNITA
10000
3636
2727
1818
909
0
0
0
0
But I expected results is:
s.n
ShgId
ShgName
MemId
MemName
YETDUE
0-30
31-60
61-90
91-120
121-180
181-365
366-689
Above_2_Yrs
1
5514
MAHALAXMI-5514
66735
SUNITA
10000
909
1818
2727
3636
0
0
0
I want only one record per member with aging .. please advice me for further action.

Similar Messages

  • App-V Reporting: SQL query for Excel Pivot Table to display App Usage (H/M/S)

    I recently posted this in the Gallery.  If anyone has any modifications or enhancements please feel free to contribute!  One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
    still published, so if anyone can figure out a crafty way to do it...  Thanks!
    http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3

    I recently posted this in the Gallery.  If anyone has any modifications or enhancements please feel free to contribute!  One thing that I'd like to be able to add to it is the ability to only display information for applications/packages that are
    still published, so if anyone can figure out a crafty way to do it...  Thanks!
    http://gallery.technet.microsoft.com/App-V-Reporting-SQL-query-6695d3c3

  • Discoverer Report - SQL Query to retrieve list of parameters

    Hi
    We have around 100 Discoverer reports and I'm trying to find the list of parameters used in each report.
    Is there any SQL query that I can use to find the parameters used for each report
    or
    should I open the reports one by one to fetch the list of parameters used.
    I checked the tables in EUL4_US schema but no luck.
    - Amarnath.K

    give this a try for starters. It looks at the custom folders defined in the business area, which is where any LOV's defined for you parameters would be. As far as looking at the workbooks themselves, no, there is no way to do that in sql.
    select
    decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') Origin,
    eb.ba_name business_area,
    eo.OBJ_TYPE,
    decode(eo.obj_type, 'SOBJ','From Database', 'CUO', 'Custom Query', 'COBJ', 'Complex Folder', eo.obj_type) obj_type_desc,
    eo.OBJ_NAME folder,
    eo.OBJ_DESCRIPTION folder_description,
    decode(eo.sobj_ext_table, NULL, NULL, eo.obj_ext_owner || '.' || eo.sobj_ext_table) base_object,
    decode(es.seg_obj_id, null, UPPER(trim(eo.obj_object_sql1)||trim(eo.obj_object_sql2)||trim(eo.obj_object_sql3))
    , UPPER(trim(es.seg_chunk1) || trim(es.seg_chunk2) || trim(es.seg_chunk3) || trim(es.seg_chunk4))) SQL
    from
    eul4_us.EUL5_BAS eb,
    eul4_us.EUL5_objs eo,
    eul4_us.EUL5_BA_OBJ_LINKS ebol,
    eul4_us.eul5_segments es
    where
    eb.BA_ID = ebol.BOL_BA_ID and
    ebol.BOL_OBJ_ID = eo.OBJ_ID and
    eo.obj_id = es.seg_obj_id (+) and
    decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') = 'Custom'
    order by
    /*decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom'), */eb.ba_name, ebol.BOL_SEQUENCE, es.seg_sequence

  • Request for report SQL Query

    hi all,
    i created links for an element but for some element links the costing and balancing codes were mistakenly given wrong and the element links are plenty so i am unable to find which is wrongly given.
    can some 1 out there provide me with the sql query that will allow me to create a report to run and confirm all the links have costing and balancing codes for all the earnings or voluntary deduction elements.
    Thank you for reading my issue. plz help!

    See if the below helps.
    Change the business group id in the query below-
    select ppf.payroll_name   
    ,pj.name Job,hou.name HR_ORG,ppg.group_name People_Group  
    ,pel.employment_category
    ,hra.location_code 
    ,pet.element_name,pet.reporting_name,pec.classification_name  
    ,pel.costable_type 
    ,pel.link_to_all_payrolls_flag 
    ,pcak1.concatenated_segments Element_Cost_Segments   
    ,pcak1.segment1  
    ,pcak1.segment2  
    ,pcak1.segment3  
    ,pcak1.segment4  
    ,pcak1.segment5  
    ,pcak1.segment6  
    ,pcak1.segment7  
    ,pcak1.segment8  
    ,pcak2.concatenated_segments Balancing_Cost_Segments  
    ,pcak2.segment1  
    ,pcak2.segment2  
    ,pcak2.segment3  
    ,pcak2.segment4  
    ,pcak2.segment5  
    ,pcak2.segment6  
    ,pcak2.segment7  
    ,pcak2.segment8  
    from pay_element_links_f pel   
    ,apps.PAY_COST_ALLOCATION_KEYFLEX  pcak1    
    ,apps.PAY_COST_ALLOCATION_KEYFLEX  pcak2    
    ,pay_element_types_f pet   
    ,pay_payrolls_f ppf   
    ,pay_element_classifications pec   
    ,per_jobs pj  
    ,hr_all_organization_units hou  
    ,PAY_PEOPLE_GROUPS ppg  
    ,hr_locations_all hra 
    where pel.element_type_id = pet.element_type_id   
    and ppf.payroll_id(+)   = pel.payroll_id
    and pcak1.cost_allocation_keyflex_id(+) = pel.cost_allocation_keyflex_id     
    and pcak2.cost_allocation_keyflex_id(+) = pel.balancing_keyflex_id     
    and  pet.business_group_id = 0   
    and pet.classification_id = pec.classification_id   
    and pj.job_id(+) = pel.job_id  
    and hou.organization_id(+) = pel.organization_id  
    and ppg.people_group_id(+) = pel.people_group_id  
    and hra.location_id(+) = pel.location_id  
    and sysdate between pel.effective_start_date and pel.effective_end_date
    and sysdate between pet.effective_start_date and pet.effective_end_date
    and sysdate between ppf.effective_start_date(+) and ppf.effective_end_date(+)
    order by ppf.payroll_name,pec.classification_namePlease close the thread, if your issue is resolved.
    Cheers,
    VB

  • SCCM 2012 All Updates report sql query

    Need build sql query for report about all MS Updates like SCCM configuration manager view in window by path:
    \Software Library\Overview\Software Updates\All Software Updates.
    But I can't find fields that can show "product" (OS that use this patch) and size of each patch in SCCM and WSUS databases. Can anybody help me?

    To get file size I create query for files in package:
    SELECT distinct ui.Title, ui.InfoURL, ui.DatePosted,
    cf.FileName, cast(cast(cf.FileSize as real)/1024/1024 as decimal(10,2)) as SizeMb, uds.AssignmentName, uds.StartTime
    FROM CI_ContentFiles cf
    INNER JOIN v_UpdateContents uc  ON cf.Content_ID  = uc.Content_ID
    INNER JOIN v_UpdateInfo ui ON uc.CI_ID = ui.CI_ID 
    INNER JOIN vSMS_UpdateDeploymentSummary uds  ON ui.CI_ID = uds.CI_ID
    join CI_ContentPackages cp on cf.Content_ID=cp.Content_ID
    join CI_Contents co on co.Content_ID = cp.Content_ID
    Where PkgID='MKL00032'
    order by ui.InfoURL

  • Report SQL query Help

    Hi,
    I am trying to call a procedure from a SQL report query. Please let me know if this is correct.
    SELECT gb.period_name,
    cc.segment1 uec,cc.segment2 dept, cc.segment3 other,
    cc.segment4 acct,cc.segment5 subacct, cc.segment6 activity,
    cc.segment7 cec, cc.segment8 subelement,cc.segment9 geo,
    cc.segment10 usind,cc.segment11 affiliate,cc.segment12 mpc,
    DECODE ( NVL (gb.begin_balance_dr_beq, 0)
    - NVL (gb.begin_balance_cr_beq, 0),
    0, ( NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0)
    NULL, ( NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0)
    NVL (gb.begin_balance_dr_beq, 0)
    - NVL (gb.begin_balance_cr_beq, 0)
    ) AS Begining_balance_functional,
    DECODE ( NVL (gb.period_net_dr_beq, 0)
    - NVL (gb.period_net_cr_beq, 0),
    0, ( NVL (gb.period_net_dr, 0)
    - NVL (gb.period_net_cr, 0)
    NULL, ( NVL (gb.period_net_dr, 0)
    - NVL (gb.period_net_cr, 0)
    NVL (gb.period_net_dr_beq, 0)
    - NVL (gb.period_net_cr_beq, 0)
    ) AS period_to_date_functional,
    (DECODE ( NVL (gb.begin_balance_dr_beq, 0)
    - NVL (gb.begin_balance_cr_beq, 0),
    0, ( NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0)
    NULL, ( NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0)
    NVL (gb.begin_balance_dr_beq, 0)
    - NVL (gb.begin_balance_cr_beq, 0)
    + (DECODE ( NVL (gb.period_net_dr_beq, 0)
    - NVL (gb.period_net_cr_beq, 0),
    0, ( NVL (gb.period_net_dr, 0)
    - NVL (gb.period_net_cr, 0)
    NULL, ( NVL (gb.period_net_dr, 0)
    - NVL (gb.period_net_cr, 0)
    NVL (gb.period_net_dr_beq, 0)
    - NVL (gb.period_net_cr_beq, 0)
    ) AS ending_balance_functional,
    NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0) AS begining_balance_entered,
    NVL (gb.period_net_dr, 0)
    - NVL (gb.period_net_cr, 0) AS period_to_date_entered,
    ( NVL (gb.begin_balance_dr, 0)
    - NVL (gb.begin_balance_cr, 0)
    + (NVL (gb.period_net_dr, 0) - NVL (gb.period_net_cr, 0)
    ) AS ending_balance_entered,
    gb.currency_code,gb.period_year, gb.period_num,
    apps.afl_gl_acct.get_value_description('ALCOA UEC',cc.segment1) UEC_Description, apps.afl_gl_acct.get_value_description('ALCOA Cost Center',cc.segment2) Cost_center_Description,
    apps.afl_gl_acct.get_value_description('ALCOA Other',cc.segment3) Other_Description,
    apps.afl_gl_acct.get_value_description('ALCOA Account',cc.segment4) Account_Description,
    apps.afl_gl_acct.get_value_description('ALCOA SubAccount',cc.segment5) SubAccount_Description,
    apps.afl_gl_acct.get_value_description('ALCOA Activity',cc.segment6) Activity_Description,
    apps.afl_gl_acct.get_value_description('ALCOA CEC',cc.segment7) CEC_Description,
    apps.afl_gl_acct.get_value_description('ALCOA SubElement',cc.segment8) SubElement_Description,
    apps.afl_gl_acct.get_value_description('ALCOA GEO',cc.segment9) GEO_Description,
    apps.afl_gl_acct.get_value_description('ALCOA US Ind',cc.segment10) US_Ind_Description,
    apps.afl_gl_acct.get_value_description('ALCOA Affiliate',cc.segment11) Affil_Description,
    afl_gl_acct.get_value_description('ALCOA MPC',cc.segment12) MPC_Description
    FROM GL.GL_BALANCES GB, GL.GL_CODE_COMBINATIONS CC,
    GL.GL_Budget_Versions GBV, GL.GL_SETS_OF_BOOKS GSB
    WHERE GB.CODE_COMBINATION_ID = CC.CODE_COMBINATION_ID
    -- And CC.SEGMENT1 = (se
    And GB.BUDGET_VERSION_ID = GBV.BUDGET_VERSION_ID (+)
    And GSB.SET_OF_BOOKS_ID = GB.SET_OF_BOOKS_ID
    and decode(gb.TRANSLATED_FLAG,'Y','Translated','Entered') =:p_currency_type
    AND cc.segment1 =:p_uec
    AND GSB.NAME = :p_sob_name
    AND gb.PERIOD_NAME= :p_period
    AND cc.segment2= nvl(:p_dept,cc.segment2)
    AND cc.segment3=nvl(:p_other,cc.segment3)
    AND cc.segment4= nvl(:p_acct,cc.segment4)
    AND cc.segment5= nvl(:p_subacct,cc.segment5)
    AND cc.segment6 = nvl(:p_activity,cc.segment6)
    AND cc.segment7 = nvl(:p_cec,cc.segment7)
    and cc.segment8= nvl(:p_subelement,cc.segment8)
    and cc.segment9= nvl(:p_geo,cc.segment9)
    and cc.segment10=nvl(:p_usind,cc.segment10)
    and cc.segment11=nvl(:p_affil,cc.segment11)
    and cc.segment12=nvl(:p_mpc,cc.segment12)
    AND gb.ACTUAL_FLAG = 'A'
    AND gb.CURRENCY_CODE = :p_currency;
    I am not completely sure of the syntax.
    Regards,
    JA

    Please let me know if this is correct.Does it compile? Does it run? Does it return the correct result.
    Please bear in mind we do not have access to your data models so we cannot run it. Nor do we know your business requirements so we cannot assess whether it implements them correctly. And it is way too big a hunk o' code for us to go through it manually.
    As a rule of thumb it is better to build a small query and get that working correctly before adding tables to it rather than building an incomprehensibly large monolith.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Filtered report SQL query in IRR

    Hi guys,
    There is simple IRR "Select * from emp" on my page.
    End user put some filters on the report from Actions Menu. Can i somehow (on any button click, etc) get the new SQL which is saved by user now?
    Thanks
    Sunil Bhatia

    See this:
    http://www.deneskubicek.blogspot.de/2013/05/getting-interactive-report-query.html
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    https://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494

  • How to get report (SQL Query) generating Run Time

    There is a Standard report of Payroll which show employee transfer information on the bases of location, grade job or organization, now to get actual query which is generated by run time in report builder including whether single column parameter or lexical parameter " because currently the query in not complicate but the parameter and lexical parameter is much more due to this not quite easy to under stand just copy past it into toad or pl/sql developer,
    Kindly share your experience to get such kind of query in you working time.
    thanks

    Here i try to explain contain of query.
    Parameter
    P_DEPTNO = 10
    P_WHERE_CLAUSE := ' AND EMPNO IS NOT NULL AND SALARY > 100'
    SELECT * FROM EMP
    WHERE DEPTNO = P_DEPTNO
    &P_WHERE_CLAUSE
    REPROT WILL GENERATE QUERY AT RUN TIME IS LIKE THAT
    SELECT * FROM EMP
    WHERE DEPTNO = 10
    AND EMPNO IS NOT NULL AND SALARY > 100
    Now i want to get this query out(Run time) by doing any oracle database feature or sth similar.
    thanks

  • Report SQL query problem

    Hi!
    I want to create a report with the script i copied at the bottom of this message. For some reason i get the following error:
    Error: Unable to describe SQL statement. Please correct it (WWV-13010)
    (WWV-)
    ORA-01001: invalid cursor (WWV-11230)
    ORA-00937: not a single-group group function (WWV-11230)
    Critical Error in wwerr_api_error.get_errors! SQL Error Message: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-01001: invalid cursor (WWV-)
    Does anybody have a clue where this is coming from? It seems to me that there are no diffucult un-SQL like things in the script.
    Thanks in advance!
    SELECT rse.name||', '||rse.initials||' '||rse.prefix "Medewerker"
    ,dpt.name "Afdeling"
    ,sum(round(act.duration *24,2)) "Aantal uren"
    ,count(distinct(sht.begin_date)) "Aantal dagen"
    ,count(distinct(ill.begin_time)) "Aantal keer"
    FROM ros.ros_departments@ROSPROD dpt
    ,ros.ros_scenarios@ROSPROD sco
    ,ros.ros_activity_types@ROSPROD aty
    ,ros.ros_activities@ROSPROD act
    ,ros.ros_duties@ROSPROD dty
    ,ros.ros_illnesses@ROSPROD ill
    ,ros.ros_shifts@ROSPROD sht
    ,ros.ros_resources@ROSPROD rse
    WHERE rse.id = sht.rse_id
    AND sht.name = 'Z'
    AND sht.begin_date <= sysdate
    AND ill.rse_id = rse.id
    AND trunc(sht.begin_date) BETWEEN trunc(ill.begin_time) AND trunc(nvl(ill.end_time,sysdate))
    AND dty.id = sht.dty_id
    AND decode(sign(dty.begin_time)
    ,-1, sht.begin_date + 1
    ,sht.begin_date)
    >= to_date('10-01-2000 00:00','dd-mm-yyyy hh24:mi')
    AND decode(sign(dty.begin_time)
    ,-1,sht.begin_date + 1
    ,sht.begin_date)
    <= to_date('10-01-2001 23:59','dd-mm-yyyy hh24:mi')
    AND sht.begin_date >= to_date('10-01-2000 00:00','dd-mm-yyyy hh24:mi') - 1
    AND sht.begin_date <= to_date('10-01-2001 23:59','dd-mm-yyyy hh24:mi') + 1
    AND act.dty_id = dty.id
    AND aty.id = act.ate_id
    AND aty.name = 'Ziek'
    AND sco.sce_rsr_id = sht.sce_id
    AND sco.status = 'PUBLISHED' -- <> 'TRIAL' en 'PLAN'
    AND dpt.id = sco.dpt_id
    AND dpt.name NOT IN ('BEEK/VKL', 'BEEK/VLA','EELDE/VKL','EELDE/VLA','ROTTERDAM/VKL','ROTTERDAM/VLA','SIM','STO','RCN','XSurvey')
    AND rse.name = :MDWPARAM
    AND dpt.name = :AFDPARAM
    GROUP BY rse.name||', '||rse.initials||' '||rse.prefix ,dpt.name
    ORDER BY 2,1

    Hi,
    Please run this sql statement in the SQL session. This way you will get the line number where the problem is happening.
    The error seems to be because the column in the select is not in the group by clause.
    Thanks,
    Sharmila

  • How to modify a SQL query?

    Hi all,
    I am using Crystal Reports version 10. I have a number of reports that have been written by a software vendor wherby the name of the database they were connected to when the report was written is coded into the FROM command of the reports SQL query, eg "GCUK_2" in the of the SQL snippet below.
    SELECT "Clients"."NAME", "Quotes"."QUOTE_ID", "Quote_Items"."UPRICE", "Quote_Items"."QTY", "Quote_Items"."UOM", "Quote_Items"."QUSAGE_ID", "Report_Control"."QUSAGEID", "Quote_Items"."STANDARD", "Quote_Items"."SECT_FLAG", "Quote_Items"."DISPORDER", "Quotes"."DESCRIPT", "Report_Control"."SECT_NAME", "Quote_Items"."CNT", "Category_and_Type"."TYPEDESC", "Quote_Items"."DESCRIPT", "Report_Control"."DISP_SORT"
    FROM   ((("GCUK_2"."schedwin"."QTE_CTRL" "Report_Control" INNER JOIN "GCUK_2"."schedwin"."QUSAGE" "Quote_Items" ON "Report_Control"."QUSAGEID"="Quote_Items"."QUSAGE_ID") LEFT OUTER JOIN "GCUK_2"."schedwin"."QUOTES" "Quotes" ON
    I have tried setting the Datasource Location, but it doesn't change the query at all. I have read on another forum that you can generate another SQL query using the Database Expert, Current Connections, then right click the Add Command for the database you want to create a SQL command. Is this the only way to update the database names in the query?
    Thanks,
    Scott.

    Hi Sourashree,
    Thanks for that. All the reports were created by the vendor using tables as opposed to the command object. I would have thought that changing the datasource would automatically cause Crystal to rewrite the SQL query syntax, but this doesn't appear to be the case.
    Yes, I've noticed that modifying the record selection will change the sql query. The only way I can see to change the database name in the query is to change to the desired databsource and then remove and re-insert the tables, which will then update the query with the correct name. However, this seems to be a convoluted way of changing the db name in the query.

  • SQL query (pl/sql function body returning query) performance issue

    I create my report in building my sql instruction with ( SQL Query pl/sql function body returning sql query );
    My report take more than 20 seconds however if i did a cut and paste with the sql code in TOAD the same sql take 1 second.
    To try to discover the source of the problem; i take the sql generated by the function and i create another report ( sql query ) this new report take 2 seconds.
    My query is very big 25,000 characters with database link.
    What is the difference between SQL-quey and sql-query(pl/sql function body returning sql query)
    Thanks
    Marc

    Marc,
    Firstly...don't compare the timings from Toad, since often Toad only fetches the first few records for you (i.e. it pages them).
    Secondly....the database link could be a factor here, but without seeing your query it's too hard to say.
    Can you post the query somewhere (on a webserver say)?

  • Can using query create aging report for GL Account

    Hi all expert,
    I have a challenge scenario which customer request print out aging report for the following GL Account.
    This is not a business partner account. However, customer want display like aging report.
    30 days aging report for the following GL accounts by projects:-
         i)     WIP (Work In Progress) account
         ii)     Accrued Revenue account
         iii)     Accrued Cost account
    Examples:
                            Current Balance       30 day   60 day  90 day   120 day
    Account  WIP         10000               2000        3000      5000     0
    Any idea or example given? If yes, can you provide a query here?
    Regards,
    Eric Tan

    Hi Eric
    In standard SAP Business One this is difficult as the reports are 2 dimensional. To achieve this you will need to write multiple select statements into a temporary table and then select the final result from the temp table. Here is a sample for you to test:
    USE [*DATABASE_NAME*]
    GO
    /****** Object:  StoredProcedure [dbo].[REPORT_NAME]    Script Date: 04/24/2009 13:17:21 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE proc [dbo].[*REPORT_NAME*]
    as
    set nocount on
    begin
    DECLARE @Day_no varchar(2)
    DECLARE @Month_no varchar(2)
    DECLARE @Year_no varchar(4)
    DECLARE @Start_Date Datetime
    SET @Day_no = DAY(GetDate())
    SET @Month_no = MONTH(GetDate())
    SET @Year_no = YEAR(GetDate())
    SET @Start_Date = @Year_No + '/' + @Month_no + '/' + @Day_no --  + '/' + @Year_No
    IF OBJECT_ID(N'tempdb..#CRDAGEING', N'U') IS NOT NULL
    drop table #CRDAGEING
    SELECT T0.[CardCode] AS [CardCode], T0.[CardName] AS [CardName], -T0.[Balance] AS [Balance], CAST(0 AS MONEY) AS [Current], CAST(0 AS MONEY) AS [1Week], CAST(0 AS MONEY) AS [2Weeks], CAST(0 AS MONEY) AS [3Weeks], CAST(0 AS MONEY) AS [4Weeks], CAST(0 AS MONEY) AS [5Weeks], CAST(0 AS MONEY) AS [6Weeks], CAST(0 AS MONEY) AS [Over6Weeks], CAST(0 AS MONEY) AS [Avg3Months], CAST (0 AS MONEY) AS [Onhand] INTO #CRDAGEING FROM OCRD T0 WHERE T0.[CardType] = 'S' -- and T0.[CardCode] <> '' --and T0.[DocDate] >= @FromDate AND T0.[DocDate] <= @ToDate
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] <= @Start_Date GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] >= DATEADD(DAY,1,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,8,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,8,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,15,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,15,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,22,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,22,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,29,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,29,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,36,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,36,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,43,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,43,@Start_Date)  GROUP BY T1.[ShortName]
    SELECT SR.[CardCode], MAX(SR.[CardName]), SUM(SR.[Balance]) AS [BalanceOwing], SUM(SR.[Current]) AS [Current], SUM(SR.[1Week]) AS [1Week], SUM(SR.[2Weeks]) AS [2Weeks], SUM(SR.[3Weeks]) AS [3Weeks], SUM(SR.[4Weeks]) AS [4Weeks], SUM(SR.[5Weeks]) AS [5Weeks], SUM(SR.[6Weeks]) AS [6Weeks], SUM(SR.[Over6Weeks]) AS [Over6Weeks] FROM dbo.#CRDAGEING SR GROUP BY SR.[CardCode] ORDER BY SR.[CardCode]
    END
    Go to Microsoft SQL Studio manager and select your company database. Then expand the list and select Programmability > Stored Procedures. Right click on Stored Procedures and select New Stored Procedure. Copy the above code over the code in the edit window and change the database name as well as report name. Then select Execute to create the stored procedure. If you make changes, remember to change the word CREATE to ALTER (with other words CREATE for the first execute, and ALTER thereafter). Then in SAP Business One create a new query and leave everything blank. Click on execute and select the pencil to change to edit mode. Remove the words SELECT and type in EXEC REPORT_NAME (change the REPORT_NAME to the name you used in SQL). Then execute again and the results will be displayed in SAP Business One.
    Let me know if you get stuck. Remember the above is an example and will need to be changed to use your tables and fields as required. The basic idea is to move across by one column with each select statement. So for example the first select statement does the CURRENT column, the second one the 30DAYS column, and so on.
    Kind regards
    Peter Juby

  • Sample query for Aging Report

    Hi! Anybody who has a sample sql query for aging report? basically this is the table structure and sample data
    bill_no B1-01 B1-02 B1-03
    bill_date 01-JAN 01-FEB 01-MAR
    previous_balance 100 600 800
    current_charges 500 200 400
    total_due 600 800 1200
    As of march 1, total due is 1200. how can i get the breakdown of 1200 as to the number of days it has been due. ex. 500 (60 days old 01-JAN to 01-MAR), 200 (30 days old), 400 (current)
    please help. thanks!
    null

    SELECT CEIL((SELECT MAX(Bill_Date) FROM Bill)- Bill_Date) Days , Previous_Balance, Current_Charges FROM Bill ORDER BY Days ASC
    Then create a matrix reprot.

  • Discoverer Report showing Null VS Show SQL query showing results !!!

    I created a simple Cross Tab Discoverer report from a custom SQL which has a calculation for balances. The output is giving all null values even though there are balances. The output doesn't seem right. So I copied the query from Tools-->Show SQL and ran the query in the TOAD where I'm showing balances for the report. I don't understand why it is not showing in the discoverer. Please help.
    Thanks
    Edited by: PA1B on Jan 27, 2010 11:40 AM

    Sorry for late reply.
    Below is the Show SQL query. I don't think the query is application dependent. C_1 is my calculation.
    SELECT o279709.SEGMENT3 as E279727,
    o279709.SEGMENT4 as E279728,
    CASE WHEN o279709.CURRENCY_CODE = 'USD' AND o279709.TRANSLATED_FLAG <> 'Y' THEN SUM(o279709.ENDING_BAL) ELSE 0 END as C_1,
    GROUPING_ID(o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG) as GID
    FROM ( --Foriegn Entity USD Balances
    SELECT                B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                  (select distinct substr(cat.COMPILED_VALUE_ATTRIBUTES,5,1) from apps.fnd_flex_values cat
                   where FLEX_VALUE_SET_ID = (select bat.FLEX_VALUE_SET_ID from apps.fnd_id_flex_structures_vl aat, apps.fnd_id_flex_segments_vl bat
                                                                                                                       where bat.id_flex_code = 'GL#' and
                                                                                                                            bat.id_flex_code = aat.id_flex_code and
                                                                                                                            aat.APPLICATION_ID = bat.APPLICATION_ID and
                                                                                                                            aat.APPLICATION_ID = 101 and
                                                                                                                            bat.SEGMENT_NAME = 'Prime Account' and
                                                                                                                            aat.id_flex_num = bat.id_flex_num
                                                                                                                            and bat.id_flex_num in (select distinct chart_of_accounts_id from apps.gl_code_combinations gat
                                                                                                                                                                              where gat.code_combination_id = A.code_combination_id))
                                       and cat.flex_value = b.segment3) ACCT_TYPE ,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,
                                       C.NAME,
    A.SET_OF_BOOKS_ID,
                                       A.CURRENCY_CODE,A.TRANSLATED_FLAG,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0)) BEG_BAL,
                                  SUM(NVL(A.PERIOD_NET_DR,0)) DEBITS,
    SUM( NVL(A.PERIOD_NET_CR,0)) CREDITS ,
    A.PERIOD_NAME,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0))+ SUM(NVL(A.PERIOD_NET_DR,0) - NVL(A.PERIOD_NET_CR,0)) ENDING_BAL
    FROM                     APPS.GL_BALANCES A ,
                                       APPS.GL_CODE_COMBINATIONS B,
                                       APPS.GL_SETS_OF_BOOKS     C
    WHERE                     A.CODE_COMBINATION_ID = B.CODE_COMBINATION_ID
    --AND                           A.PERIOD_NAME = 'SEP-09'
    AND                          C.SET_OF_BOOKS_ID = A.SET_OF_BOOKS_ID
    --AND                           A.TRANSLATED_FLAG <> 'Y'
    --AND                           B.SEGMENT1 = '83101'
    --AND                           B.SEGMENT3 = '14602'
    --AND                           A.SET_OF_BOOKS_ID = 77
    --AND                           A.CURRENCY_CODE = 'USD'
    GROUP BY           A.CODE_COMBINATION_ID,
                                  B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,          
                                       A.CURRENCY_CODE,
                                       A.TRANSLATED_FLAG,
                                       C.NAME,A.PERIOD_NAME,
    A.SET_OF_BOOKS_ID
    ) o279709
    WHERE (o279709.PERIOD_NAME = 'DEC-09')
    AND (o279709.SET_OF_BOOKS_ID <> 72)
    AND (o279709.SEGMENT12 = '000')
    AND (o279709.SEGMENT3 IN ('10101','10301','10502','12001'))
    AND (o279709.SEGMENT1 IN ('82901','82902','82903','83001','83003','83201'))
    GROUP BY GROUPING SETS(( o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG ),( o279709.SEGMENT3,o279709.SEGMENT4 ),( o279709.SEGMENT3 ))
    HAVING (GROUP_ID()=0)
    ORDER BY GID DESC;
    Thanks,
    PA1
    Edited by: PA1B on Jan 29, 2010 12:50 PM

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

Maybe you are looking for

  • IDE Channel set up advise ?

    I have always understood that the optimum IDE set up is to keep hard drives together and CDROM's and DVD together. I understood that if I combined the CDROM on the same IDE as a HD, that the IDE speed would be reduced to the lowest common demoninator

  • Qyery returning empty result using dbms_xmlgen doesn't work as expected

    Hi group. I'm using the following code in a PSQL procedure procedure selectXML(consulta in varchar2,xmlout out clob) as context dbms_xmlquery.ctxtype; resultado clob; tam integer; context_gen dbms_xmlgen.ctxHandle; begin IF useDBMS_XMLGEN THEN BEGIN

  • Drag & Drop Game - I'm stuck!

    Hello. I'll try and explain this as simply as I can! I have a drag and drop game where you have to drag one of 4 items into a bag. If you chose the right item and drag that into the bag, you'll jump to a specific marker which says CORRECT. If you dra

  • Transfer posting to special stock sales order with different material

    I am able to MB1B a material  (Transfer posting) using mvt 412 E and transfer from own stock to sales order stock ,where Sales order belongs to a different material. It should not allow posting to a "E" stock to a sales order of different material. (

  • Digital waveform editor can not open hws file generated by niHWS store waveform

    Hi, I am using a simple VI to store the U32 array to a hws file in LabVIEW, however, the file generated can not be opened by Digital Waveform Editor. The VI used to be working well before I upgrade LabVIEW from V7 to V7.1. Meanwhile I also found out