SQL Member Count by Month

Hello,
I have a table with member's effective date, termination date, plan and name, something like below.
I would like to know how many members exist by month based on the effective and terminate date.
Then, need to develop a report in SSRS with parameters;
if a user select a parameter from and to date as below, the report will populate the sum of members who are active in the month.
I believe that I need to query in SQL to create a column that somehow be able to count members monthly..
but I am not sure how.
What is the best way? Any advise please?

Hi YJB5151,
When populating the report dataset, we need to add another two columns: one to represent the current Year, and the other one to represent the current month. Besides, the query groups by Plan column, Name column, Year column, and Month column.
In the report, we drag a Matrix to the design surface, add field Name to the row group and Month field to the column group. Then, add a parent row group that groups on filed Plan, and a parent column group that groups on field Year. In
the data area of the matrix, fill in the cell with expression =Count(Fileds!Effective.Value).
Add two static rows outside the row groups: one for Plan A and one for Plan B. In the proper cell of the Plan A row, input the expression: =sum(iif(Fileds!Pan.Value="Plan A", 1,0)). In the proper cell of the Plan B row, input the expression:
=sum(iif(Fileds!Pan.Value="Plan B", 1,0)).
Hope this helps.
Regards,
Mike Yin
TechNet Community Support

Similar Messages

  • Why is member count 100 for all users sccm collection

    hello,
    I have SCCM 2012 SP1 -4, and have enabled user discovery but "all users" collection does not goes above 100 member count.
    I do have more 1500 users in AD, all related setting are at default.
    Disable \enabling was no help, 
    no component shows warning or error.
    Thanks

    Hi. what about adusrdis.log? and are you correctly configuring AD user discovery? see this for example
    http://www.windows-noob.com/forums/index.php?/topic/4428-using-sccm-2012-rc-in-a-lab-part-3-configuring-discovery-and-boundaries/

  • Issue with SQL%BULK_EXCEPTIONS.COUNT in Oracle 9iR2

    Hi All,
    We are using the Oracle 9i Database
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE 9.2.0.7.0 Production
    TNS for HPUX: Version 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - Production
    I am facing an issue when using SQL%BULK_EXCEPTIONS.COUNT.
    Getting the below error when executing the below dummy block.
    DECLARE
    ERROR at line 1:
    ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 12
    ORA-06510: PL/SQL: unhandled user-defined exception
    DECLARE
    e exception;
    cnt number;
    BEGIN
    NULL;
    raise e;
    exception
    when others then
    if SQL%BULK_EXCEPTIONS.COUNT>0 then
    null;
    end if;
    dbms_output.put_line(1);
    END;
    Request to let me know what is the issue.
    FYI: I never faced this issue in 10gr2 and 11gr2.
    Thanks,
    Madhu K.

    Where are you using a BULK COLLECT with a SAVE EXCEPTIONS that would initialize the SQL%BULK_EXCEPTIONS collection?
    FYI: I never faced this issue in 10gr2 and 11gr2.Are you sure about that? If I run the code you posted in my 11.2 database, I get the same error
    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    e exception;
      3    cnt number;
      4  BEGIN
      5    NULL;
      6    raise e;
      7  exception
      8    when others then
      9      if SQL%BULK_EXCEPTIONS.COUNT>0 then
    10        null;
    11      end if;
    12    dbms_output.put_line(1);
    13* END;
    SQL> /
    DECLARE
    ERROR at line 1:
    ORA-06531: Reference to uninitialized collection
    ORA-06512: at line 9
    ORA-06510: PL/SQL: unhandled user-defined exceptionJustin

  • Update member  count error for essbase cube

    Whenever i import a cube from essabse into obiee. i get the following error when i click on "update member count" on any member in the Physical layer of the obiee administration.
    this problem comes even if i import a different cube, meaning this is not due to essbase error.
    [NQODBC][SQL_STATE:HY0000][nQSError: 10058] A general error has occurred.
    [nQSError:43093] An error occured while processing the EXECUTE PHYSICAL statement.
    Essbase Error: Unknown Member Measures.xxxyyyxxxCount used in query
    kindly help!!

    i am using version 11.1.1.3
    i have created an holap cube in Essbase integration services. i have created olap model using rdbms source in the EIS. however i am unable to access the rdbms level(hybrid analysis enabled) data of the essbase cube in obiee.

  • Count of month

    Hi There,
    I have SSRS 2008R2, and I have data source from ssas, has YTD Amount from the cube, I want to add calculation in report to calculate average YTD, so if we are in April, then Avg YTD would be YTD Amount/number of month (4) in this case.
    How do I get count of month here
    Thanks
    Don

    Hi Don,
    Per my understanding that you want to get the Avg YTD based on the month number you have selected, right?
    I assumed that you have a field may be Date type field to get the month number from and map with an Amount field. I have tested on my local environment and you can create an parameter of the Month, when you select an month number you will get the Avg YTD=SUM(YTD
    Amount)/Number.
    Details information below for your reference:
    Create an parameter(Month) to specify 1,2,3,4,5,6,7,8,9,10,11,12 as the value for the available values of this parameter
    add an filter in the Dataset as below to filter the YTD data based on the Month Number:
    Expression: =DatePart("m",Fields!Date.Value)
    Operator:   < =
    Value:       =Parameters!Month.Value
    Using below expression to get the Avg YTD:
    =Sum(Fields!YTD_Amount.Value)/SUM(Count(Fields!YTD_Amount.Value))
    Or:
    =Sum(Fields!YTD_Amount.Value)/Count(Fields!YTD_Amount.Value,"DataSetName")
    Preview as below:
    If your problem still exists, please try to provide sample data in the table and also the table structure.
    Regards
    Vicky Liu
    If you have any feedback on our support, please click
    here.
    Vicky Liu
    TechNet Community Support

  • All Users and User Groups member count 0

    I've setup SCCM 2012 R2, configured the AD User Discovery. But my Member count for All Users and User groups is 0, Memebers Visible on Site is 968. 
    I'm not sure how to get the Member count working. 

    Hi,
    Please check Smsprov.log to see whether there are any errors when you open Device Collections.
    Best Regards,
    Joyce
    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.

  • SQL Version Count in AWR and Child Cursor

    Hi,
    In 11.1.0.7, what is SQL Version count in AWR report? What does it mean? and how oracle does this version count? How do we define child cursor?
    Thanks

    Hi,
    when you issue a SQL statement, the database searches the library cache to find a cursor with matching SQL text. Then it can happen that even though the text matches, there are some other differences that prevent you from using existing cursor (e.g. different optimizer settings, different NLS settings, different permissions etc.). In such cases, a new child cursor is created. So basically child cursors are different versions of the same SQL statement.
    If you have SQL statements with thousands of versions, this could mean a problem for your shared pool (child cursors taking up lots of space and causing fragmentation), as well as a potential for performance problems due to plan instability (if the same SQL text is parsed to a new plan every time, sooner or later it will be a bad plan). That's why AWR report has this list.
    According to Oracle support, up to a couple of hundreds versions doesn't indicate a problem (cursor sharing mechanism isn't perfect), but when you have thousands or tens of thousands of versions, you should check your cursor sharing settings (first of all, CURSOR_SHARING parameter).
    Best regards,
    Nikolay

  • What is the problem with native dynamic sql when counting rows in all table

    what is the problem with native dynamic sql when counting rows in all table?Giving an error "table or view does not exist". Thanks.
    DECLARE
    v_sql_string varchar2(1000);
    v_no_of_rows number;
    BEGIN
    for i in ( select table_name from all_tables )
    loop
    v_sql_string := ' select count(1) from ' || i.table_name;
    dbms_output.put_line( v_sql_string );
    --execute immediate v_sql_string into v_no_of_rows;
    end loop;
    END;

    Usually your problem can be described with 'Who cares'. I mean, for what reason do you do this? I doubt that there's a business need to get 100 % accurate answers for this. Normally such things are used to get a picture about the growth of data.
    Personally I would prefer to have up-to-date statistics for all tables and just query the number of rows from there. Sufficient for me in < 99 % of all cases.
    Just my $ .02...

  • Sum(sales) count for month year and week

    I have sales table : pord_id number, sale_date date
    my question: a) i need to populate sum of sales for week ie., from today to 7 days example 20-MAY-2007 to 27-MAY-2007
    b) sum of sales for month of MAY this year 2007
    c) sum of sales for 20-MAY-2006 last, only day
    Please help me with this query.. URGENT

    This..?
    sql>select * from sale;
    PROD_ID SALES_DATE
    2  02-MAY-07 
    3  03-MAY-07 
    4  04-MAY-07 
    5  05-MAY-07 
    7  07-MAY-07 
    8  08-MAY-07 
    10  10-MAY-07 
    11  11-MAY-07 
    12  12-MAY-07 
    13  13-MAY-07 
    14  14-MAY-07 
    15  15-MAY-07 
    16  16-MAY-07 
    17  17-MAY-07 
    18  18-MAY-07 
    19  19-MAY-07 
    20  20-MAY-07 
    22  22-MAY-07 
    23  23-MAY-07 
    24  24-MAY-07 
    26  26-MAY-07 
    27  27-MAY-07 
    28  28-MAY-07 
    29  29-MAY-07 
    30  30-MAY-07 
    25 rows selected.
    sql>
    select sum(case  sales_date when trunc(sysdate)  then 1 else 0 end) day_sum,
             sum(case when sales_date between sysdate and sysdate+7 then 1 else 0 end) week_sum,
             sum(case when sales_date between trunc(sysdate,'month') and last_day(sysdate) then 1 else 0 end) month_sum,
            count(*) year_sum
    from sale
    where to_char(sales_date,'yyyy') = to_char(sysdate,'yyyy');
    DAY_SUM WEEK_SUM MONTH_SUM YEAR_SUM 
    1  5  25  25
    Message was edited by:
            jeneesh
    Note: Truncated dates were inserted in the table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How would I create a Summary Chart for the Current Year Using a Count by Month?

    Post Author: MarkS
    CA Forum: Charts and Graphs
    I have a data set of 3 date fields.  I would like to create a summary counting all of the occurrances of each of these dates per month, similar to using a SumProduct() command in excel.
    For example, my data is as follows:
    Registered Date  |    Application Date   |   Sale Date
    1/1/2007             |      2/1/2007            |     2/20/2007    
    1/10/2007           |      2/1/2007            |     3/20/2007
    2/20/2007           |      3/10/2007          |     3/20/2007
    I would like to summarize this information by month as follows:
                          |  Jan '07   |   Feb '07  |  Mar '07  |  TOTAL
    Registered      |      2        |   1           |    0         |   3
    Applications    |     0         |   2           |   1          |  3
    Sales             |     0         |   1            |  2            |  3
    TOTAL           |   2            |  4            |  3            | 9
    Is there any way to do this?

    Post Author: V361
    CA Forum: Charts and Graphs
    Yes, but it will require some effort. Group on "Sale Date"  Change the group to group by month.   You can then create a running total for "Registered Date","Application Date"," Sale Date"      For Registered date, I used Field to summarize Registered Date,  Type of summary was count, Evaluate use a formula, reset on change of group 1 (I only have one group, "Sale Date")  The formula will look like this.
    month ({Registered Date  }) in &#91;1,2,3,4,5,6,7,8,9,10,11,12&#93;
    You would build your other running totals (Counts) using the same methods,
    Once you have these, you should be able to create your chart.

  • OBIEE: Incorrect SQL - with count function uses ORDER BY instead GROUP BY

    I made a basic report that is a client count; I want to know how many clients the company have.
    But, when I run this report, OBIEE generates a ORDER BY sentence, instead a GROUP BY. Remember that I'm using count function, that is a agregation.
    The SQL generated was:
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    order by c1
    The error that I receive is:
    "Query Status: Query Failed: [nQSError: 16001] ODBC error state: S1000 code: -1005018 message: [Sybase][ODBC Driver][Adaptive Server Anywhere]Illegal ORDER BY item Order Item: 'N0',
    -- (opt_OrderBy.cxx 429) .
    [nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement."
    If I substitute ORDER BY with GROUP BY and test it in Sybase, Ithe query runs without any problem.
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    group by c1
    Do you know why OBIEE generates this SQL??? Why uses, with a aggregation function, a ORDER BY and not a GROUP BY? How can I resolve this problem???
    Regards,
    Susana Figueiredo

    Verify your repository design and make sure that you have defined count aggregate on fact column. You would also need to define the content level of each dimension in fact table.

  • Sql aggregate help using month

    Hello guys.. I need your help in the below query..
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    create table test_12 ( co_cd varchar2 (10),
    dt date,
    sale number(10));
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC','01-09-2000','250.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC','04-09-2000','350.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC','01-12-2000','450.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('CO','01-09-2000','950.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('CO','05-09-2000','250.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('TI','07-09-2000','750.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC','09-09-2000','150.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('AB','02-09-2000','850.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('AB','01-09-2000','250.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('TI','04-09-2000','850.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC','06-09-2000','550.00');
    insert into test_12 (CO_CD,DT,SALE) VALUES ('CO','02-09-2000','250.00');
    COMMIT;
    the target data should be aggregated sales for last 15 months of data for each company code
    CO_CD JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
    CO 950 250 0 0 0
    TI 0 0 850
    thanks

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statements. That really helps to understand the problem, and to make sure that the answers actually do work.
    If you post code that doesn't work, then it's not so helpful. None of your INSERT statements work for me. They may work for you, depeneing on you NLS settings, but you sshouldn't use strings, such as '01-09-2000' in place of a DATE. Use TO_DATE to convert string like that into DATEs.
    Also, don't INSERT strings like '250.00' in place of a NUMBER. Lose the quotes. so it would be better if you posted statements like this:
    insert into test_12 (CO_CD,DT,SALE) VALUES ('LC', TO_DATE ('01-09-2011',  'MM-DD-YYYY'), 250.00);How do you get the results you posted for that sample data? It looks like none of the dts are in the last 120 months, let alone the last 15 months.
    Why do you want output rows for co_cds 'CO' and 'TI', but not for 'AB' and 'LC'?
    Please format your output, so people can tell which number is in which column. Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If the "last 15 months" means the 15 consecutive months ending with the current calendar month, then you can do something like this:WITH     got_month_num     AS
         SELECT     co_cd
         ,     MONTHS_BETWEEN ( TRUNC (SYSDATE, 'MONTH')
                   , TRUNC (dt,      'MONTH')
                   ) AS month_num
         ,     sale
         FROM     test_12
         WHERE     dt     >= ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), -14)     -- For efficiency
         AND     dt     < ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), 1)
    SELECT     *
    FROM     got_month_num
    PIVOT     (     SUM (sale)
         FOR     month_num IN ( 0     AS this_month
                   , 1     AS "1 Month Ago"
                   , 2     AS "2 Months Ago"
                   , 14     AS "14 Months Ago"
    ORDER BY co_cd
    If "the last 15 months" means something else, then just change the definition of month_num in the sub-query.
    If you want less generic column names (e.g. 'APR_2011') that change automatically, depending on when the query is run and/or what data is found in the table, then you have to use dynamic SQL.  This isn't very hard in SQL*Plus: you can do a separate preliminary query to set sione substritution varaibles, and then use those variables as the column alaises in the PIVOT clause.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SQL Statement / Count & Percentage

    Hello All,
    Below is the SQL statement that I'm using with an MS Access database. Now, I'm looking for an SQL statement that will get the same results using an SQL Compact database.
    Here is what I am using with MS Access that works great:
    queryString = "SELECT DStatus, Count(DStatus) As CountOfSummaryItem, (Count(*)/(Select count(*) FROM tbl_Records_DR)) as Percentage From tbl_Records_DR GROUP BY DStatus Order BY Count(DStatus) DESC;"
    Results are something like this out of a total 50 records in the database:
    Status   -   Count  -   Percentage
    Broken   -   5     -   10%
    Stopped -   10   -   20%
    Return   -   20   -   40%
    Closed   -   15   -   30%
    Thanks,
    ADawn
    ADawn

    SQL Server Compact has limited support for subqueries. I would suggest:
    SELECT DStatus, Count(*) FROM tbl_Records_DR GROUP BY DStatus
    to get the record count per "DStatus", and load the results on a generic List<> object, where you would do the math in code, or else, get first the total record count into a int variable, executing a scalar command with the following instruction
    (C#):
    SqlCeCommand totalCountCommand = new SqlCeCommand("SELECT Count(*) FROM tbl_Records_DR", myConnection);int i = (int)totalCountCommand.ExecuteScalar();
    ...and then use that value on the following instruction, either using string concatenation or a command parameter to divide each value fot the total count...
    SqlCeCommand rowCountCommand = new SqlCeCommand("SELECT DStatus, Count(*), Count(*)/" + i.ToString() + " * 100 AS Percentage FROM tbl_Records_DR GROUP BY DStatus", myConnection);SqlCeDataReader r = rowCountCommand.ExecuteReader();
    This is not tested code, it's just meant to give you an idea on how to get the result.
    Alberto Silva Microsoft MVP - Device Application Development - http://msmvps.com/AlbertoSilva moving2u - R&D Manager - http://www.moving2u.pt

  • PL/SQL LOOP or INSERT MONTH

    I have a table below that has START_DATE and END_DATE for each record but not individual row for each month. So, a record can have 6 months payment with start date - '20100101' to end_date 20100630.
    I need to find out payment for each month for recon.
    I want to add that month field and keep everything else exactly the same as what's in table.
    For above example it should add
    01-JAN-2010 ................................................ <--- everything else same
    01-FEB-2010 ........................
    |
    |
    |
    01-JUN-2010 ..........................................................
    The helpful fields are START_DATE, END_DATE, NO_OF_MONTHS1 and NO_MONTHS_2. Somethimes, NO_MONTH1 and NO_MONTHS_2 differ. Normally whe they differ, one is 00.
    --oracle 10g
    --DROP TABLE PAYMENTS;
    CREATE TABLE PAYMENTS
    CMPNY VARCHAR2,
    S_ID VARCHAR2,
    NO_MONTHS_1 VARCHAR2,
    NO_MONTHS_2 VARCHAR2,
    ADJ_CODE VARCHAR2,
    START_DATE VARCHAR2,
    END_DATE VARCHAR2,
    AMOUNT NUMBER
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S001','02','02','20','20090801','20100930','100');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S002','02','02','20','20090801','20100930','100');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S002','01','01','12','20090101','20090131','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','00','04','18','20090101','20090430','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S003','00','02','12','20090501','20090731','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S004','01','01','12','20090101','20090131','50');
    commit;
    RESULTS should be something like
    CREATE TABLE PAYMENTS1
    ELIGIBLE_MONTH DATE,
    CMPNY VARCHAR2,
    S_ID VARCHAR2,
    NO_MONTHS_1 VARCHAR2,
    NO_MONTHS_2 VARCHAR2,
    ADJ_CODE VARCHAR2,
    START_DATE VARCHAR2,
    END_DATE VARCHAR2,
    AMOUNT NUMBER
    commit;
    --BELOW IS AN EXAMPLE OF HOW THE SOLUTION SHOULD COMEOUT FOR FIRST 3 RECORD IN ABOVE TABLE
    ---for first record in above table, it should create 6 rows, and apply eligible_month to it
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2010','C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-FEB-2010','C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAR-2010','C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-APR-2010','C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAY-2010','C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JUN-2010','C001','S001','06','06','20','20100101','20100630','30');
    ---IT SHOULD CREATE 4 ROWS
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2009','C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-FEB-2009','C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAR-2009','C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-APR-2009','C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-AUG-2010','C002','S001','02','02','20','20100801','20100930','100');
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-SEP-2010','C002','S001','02','02','20','20100801','20100930','100');

    Hi,
    788729 wrote:
    I have a table below that has START_DATE and END_DATE for each record but not individual row for each month. So, a record can have 6 months payment with start date - '20100101' to end_date 20100630.
    I need to find out payment for each month for recon.
    I want to add that month field and keep everything else exactly the same as what's in table.
    For above example it should add
    01-JAN-2010 ................................................ <--- everything else same
    01-FEB-2010 ........................
    |
    |
    |
    01-JUN-2010 ..........................................................This seems to be an easier variation of your last question:
    Re: PL/SQL LOOP MONTH
    You should have some idea about how to do it by now. Post your best attempt.
    The helpful fields are START_DATE, END_DATE, NO_OF_MONTHS1 and NO_MONTHS_2. Somethimes, NO_MONTH1 and NO_MONTHS_2 differ. Normally whe they differ, one is 00.What is the role each of those columns plays in this problem? Which one(s) tell how many rows need to be inserted? Why are the others helpful?
    >
    >
    --oracle 10g
    --DROP TABLE PAYMENTS;
    CREATE TABLE PAYMENTS
    CMPNY VARCHAR2,
    S_ID VARCHAR2,
    NO_MONTHS_1 VARCHAR2,
    NO_MONTHS_2 VARCHAR2,
    ADJ_CODE VARCHAR2,
    START_DATE VARCHAR2,
    END_DATE VARCHAR2,
    AMOUNT NUMBER
    );Don't use VARCHAR2 columns to store dates; alwyas use DATE (or TIMESTAMP) columns.
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','06','06','20','20100101','20100630','30');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','04','04','12','20090101','20090430','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S001','02','02','20','20090801','20100930','100');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S002','02','02','20','20090801','20100930','100');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S002','01','01','12','20090101','20090131','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','00','04','18','20090101','20090430','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S003','00','02','12','20090501','20090731','50');
    INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S004','01','01','12','20090101','20090131','50');
    commit;Thanks for posting the CREATE TABLE and INSERT statemnets.
    RESULTS should be something like
    CREATE TABLE PAYMENTS1
    ELIGIBLE_MONTH DATE,
    CMPNY VARCHAR2,
    S_ID VARCHAR2,
    NO_MONTHS_1 VARCHAR2,
    NO_MONTHS_2 VARCHAR2,
    ADJ_CODE VARCHAR2,
    START_DATE VARCHAR2,
    END_DATE VARCHAR2,
    AMOUNT NUMBER
    commit;
    --BELOW IS AN EXAMPLE OF HOW THE SOLUTION SHOULD COMEOUT FOR FIRST 3 RECORD IN ABOVE TABLEWhy only 3? Post the results that you want from the sample data. If 3 rows is enough to show what the problem is, why did you post 8 rows above? If 8 rows give a better picture of the problem, why not show the results from 8 rows?
    >
    ---for first record in above table, it should create 6 rows, and apply eligible_month to it
    INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2010','C001','S001','06','06','20','20100101','20100630','30');There are 8 columns listed before the VALUES keyword, but 9 values given after it.
    There is no eligible_month column in paymemts. Did you mean payments<b>1</b>?
    Do you want a query that produces these INSERT statements as strings, or do you actually want to populate payments1 (or payments)?
    If you just want to populate a table, show the contents of the populated table in a form people can read and understand, for example:
    ELIGIBLE_MONTH  CMPNY  S_ID  NO_MONTHS_1  NO_MONTHS_2  START_DATE  END_DATE  AMOUNT
    01-JAN-2010     C001   S001  06            06            20100101        20100630  30
    01-FEB-2010     C001   S001  06            06            20100101        20100630  30
    ...When you post formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL distinct count

    Hi..
    Can anyone tell me how to do the SQL
    SELECT EMPNO,DISTINCT(COUNT(SALARY))
    FROM EMPLOYEE
    Thanks in Advnace......
    Rajeshwari

    You need to count the distinct account_keys in the account table as an in-line view and join that to the product table. Something like:
    SELECT p.product_key, p.name, a.cnt
    FROM product p,
         (SELECT product_key, COUNT(DISTINCT account_key) cnt
          FROM account
          GROUP BY product_key) a
    WHERE p.product_key = a.product_keyAlthough, your sample data gives odd results because there are two entries for p1 A and product p4 has two names D and B, although since it does not appear in accounts, it makes no differene in this particular case.
    If you actually want to show all of the products from the product table and a zero count if they do not appear in accounts, then you need an outer join, something like:
    SELECT p.product_key, p.name, NVL(a.cnt, 0) cnt
    FROM product p
    LEFT JOIN (SELECT product_key, COUNT(DISTINCT account_key) cnt
               FROM account
               GROUP BY product_key) a
       ON p.product_key = a.product_keyHTH
    John

Maybe you are looking for

  • Why use an interface?

    Hey everybody, I posted a message in another thread about why to use an abstract class. I have another question and again I am not asking how but why and when. But this time about interfaces. Why would I need to write one? Any example that is not too

  • Query erroring with OutOfMemory exception

    Hi, When I run this query: SELECT VENDPACKINGSLIPTRANS.COSTLEDGERVOUCHER, VENDPACKINGSLIPTRANS.ITEMID, VENDPACKINGSLIPTRANS.INVENTTRANSID,VENDPACKINGSLIPJOUR.PURCHID, VENDPACKINGSLIPTRANS.NAME, VENDPACKINGSLIPTRANS.QTY FROM VENDPACKINGSLIPTRANS INNER

  • [solved] KDE4 AltF2 no "Run Command" option, only works with menu apps

    Well, in Kubuntu, when I pressed Alt F2, and typed 'kdesudo nvidia-settings' (for example), which wasn't in the menu, there was an option to simply run the command (like with GNome, KDE3, and pretty much everything else), but on here, it doesn't show

  • Muse Mac version - freezing on right click

    Hi, I have recently subscribe to the annual plan of Muse. I use Muse on 2 stations: a Mac Pro with Montain Lion and on a Dell laptop with Windows 7. When I start Muse on my Mac and use the right click... I've got the beach ball of dead every time and

  • My ipod went through the washing machine!

    Ok, i have a 1GB shuffle and not realizing it was still in my pants, it went through the wash and dryer. Is there anyway to salvage it?