How to determine how many times result set columns have same value

Hi -
I'm doing a report which will be used for payment trend analyses.
My initial result set looks like this:
HOUSEHOLD_ID     JAN_PMT     FEB_PMT     MAR_PMT     APR_PMT     MAY_PMT     JUN_PMT     JUL_PMT     AUG_PMT     SEP_PMT     OCT_PMT     NOV_PMT     DEC_PMT
90026845409     1     1     1     1     2     1     1     1     1     0     1     0(many rows, of course; result set pivoted)
I need to determine the households that have a > 0 value in three or more consecutive months.
I'm hoping someone will have some suggestions because the only solutions I'm coming up with right now would be a coding nightmare (lots of "OR's"), and I'm assuming (hoping) there's a better solution out there.
Thanks!
Christine

Hi Frank,
I'm not sure I'm understanding how I would use those analytic functions. Here is my select statement:
SELECT HOUSEHOLD_ID,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS JAN_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS FEB_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS MAR_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS APR_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS MAY_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS JUN_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS JUL_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS AUG_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS SEP_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS OCT_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS NOV_PMT,
       SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                     ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                THEN 1 ELSE 0 END) AS DEC_PMT
  FROM MONETARY_TRANS
WHERE MONETARY_TRANS_TYPE_ID    = 1                             --payment
--TESTING
AND HOUSEHOLD_ID = 90026845409
   AND RESPONSIBLE_PARTY_TYPE_ID = 1                             --household
   AND RECEIVED_DATE > '01-JAN-2008'
   AND ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6
    OR   TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 )
   AND PREMIUM_AMOUNT            > 0
   AND BILLING_TRANS_TYPE_ID     = 6
   AND MONETARY_TRANS_TYPE_ID    = 1
   AND RESPONSIBLE_PARTY_TYPE_ID = 1
GROUP BY HOUSEHOLD_IDAnd from this I get the results originally posted. From there I need to figure out the households that have values greater than 0 for three or more consecutive months.
Thanks for your help........
-Christine

Similar Messages

  • I cannot get the subtitles to work no matter how many times I set it up and I am doing it correctly, what is wrong?

    I cannot get the subtitles to work no matter how many times I set it up and I am doing it correctly, what is wrong?

    if the material don't state there is subtitles in your language it don't include it
    and if will only show subtitles if the language you choose in the atv settings so if you have it set to french
    and the material only have subtitles in English and not french they will not display

  • How should i use the two results sets in one single report data region?

    Hi frnz,
     I have to create a report using the below condition...
    Here my given data  set query gives you the two result sets ,so how should i use that two result sets information in single report....when i accessing that data set query it will take the values off the first result set not for the second result set.
    without using sub report and look up functionality..... if possible
    is there any way to achieve this.....Please let me know..
    Thanks!

    You cant get both resultsets in SSRS. SSRS dataset will only take the first resultset
    you need to either create them as separate queries or merge them into a single resultset and return with ad additional hardcoded field which indicates resultset (ie resultset1,resultset2 etc)
    Then inside SSRS report you can filter on the field to fetch individual resultsets at required places. While merging you need to make sure metadata of two resultsets are made consistent ie number of columns and correcponding column data types should be same.
    In absence of required number of columns just put some placeholders using NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • When I try to update an app in the App Store i get a message "There was an error in the App Store. Please try again later. (13)"  I have tried many many times and keep getting the same message.  How do I resolve?

    When I try to update an app in the App Store i get a message "There was an error in the App Store. Please try again later. (13)"  I have tried many many times and keep getting the same message.  How do I resolve?

    First take the steps recommended in this support article. If there's no change, continue as follows.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Cookies/com.apple.appstore.cookies
    Right-click or control-click the line and select
    Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item selected. Quit the application if it's running. Move the selected item to the Trash. Relaunch the application and test.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • How to determine how long an Oracle patch will take to complete?

    Hello,
    Does anybody know of a way as to how to determine how long a certain Oracle patch will take when it is applied?
    Regards.

    Another thing to consider is if the patch does any data conversion/inserts/updates/validation/etc. Running a patch against a small test instance with 100 users and 10,000 invoices may take considerably less time than it does against a production size instance with 22,000+ users and millions of invoices.
    We try to test every patch against a production size test instance prior to implementing it into production.

  • How to make New Document and Upload Document to have same Content Type in Document Library in Sharepoint 2010

    Hi,
    How to make 'New Document' and 'Upload Document' to have same content type(Custom) in Document Library in Sharepoint2010.
    Note : I have created custom Content Type since I have custom columns along with upload column..
    Regards, Shreyas R S

    go to library settings 
    Change new button order and default content type
    set your custom content type to be #1
    when you upload new document it will automatically have your custom content type
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • How do I break up a result set over various pages?

    I would like some example code of how to breakup a result set that I am using in a form.
    There are too many results for the form to currently work properly on one page so I have to do it over several web pages, using a next page link etc...
    I am currently using servlets.
    If anyone has an idea of how to do this differently have at it and let me know what to do. I prefer code examples.

    I would change the select query so that it doesn't return the whole resultset. Check your database manual to see if your database supports something like limit. E.g. this query will only return the 20 first records if you are using mysql.
    select *
    from tablename
    limit 0,20
    Kaj

  • How Many Times Can I Use The Same Serial Number For Adobe Creative Suite 4?

    I have design standard and was told I can use the same serial number on multiple computers. How many time can I use it? And say I install it on the maximum number of computers, but get a new computer, can I uninstall it on one of the old computers and use it on the new one? And can I use the programs on both computers simultaneously or do I have to use them one at a time?

    Fred Tech wrote:
    Broadly speaking, it depends on the type of license you have.
    Specifically, if you have a single license then officially, you should only install it once on one computer.
    Practically, (unless it has changed with CS4) you maybe able to install it on more then one computer, BUT can only run one instance of the software at a time. You can not run more then one instance of the software concurrently; i.e. you can't run Dreamweaver on Computer 1 and Photoshop on Computer 2. That would be two instances, and is not permitted.
    This is my understanding. I am happy to be corrected if I am wrong
    Fred
    Sorry Fred you are wrong.
    If you have a single license you can install it on as many computers as you like. you can only activate the suite on two computers at anyone time. Work and Home or as many of us do it Desktop and Laptop. You can not use the computers simultaneously. You only have 20 activation/deactivations so use them wisely. Student versions only have one activation. You can not break up the suite installs the suite is considered one application.

  • How can I use a Lookup task to lookup from my SQL Result set and have a join

    So in my Control Flow, I have an Execute SQL Task which gets my Table result set. I then have a Foreach Loop Container that iterates through the result set and a Data Flow. The first task in the Data Flow is an OLE DB Source SQL Command that retrieves data
    columns associated with my result set. I then do a Derived Column so I can SUBSTRING from one of my data columns and now I want to perform a Lookup to my Application Database.
    How do I code my Lookup task to utilize my SQL Result set variable and match on it? I cannot use the GUI for the Lookup task as my Lookup has to have some JOINS in it.
    Thanks for your review and am hopeful for a reply.

    Can you expand on that? I'm sorry but I am new and a novice to the SSIS world and I want to do this as best I can and as efficiently as I can. Are you saying that Rajen's way suggested above is the way to go?
    A little background....external data from a 3rd party client. I'v staged that external data to a SQL Server staging table. I have to try and match that data up to our database using SSN, DOB, and Gender...and if I can't match that way then I have to try
    and match by Name. I need to make sure that there is only one and only one account for that match. If I cannot match and match one and only one, then I'll create rows on a DataAnomaly Table. If I do match, then I have to check and make sure that there is only
    one and only one Member span for that match. Similarly handle the data anomaly and then check and make sure there is a "Diabetes" claim and similarly handle the DataAnomaly accordingly.
    That's where I'm at. Sooooo are you saying to use Rajen's suggestion? I don't think I can do that because I need multiple SQL tasks and I cannot connect multiple OLE DB Source tasks.
    Any help and suggestions are greatly appreciated.
    Thanks.

  • How to determine the latency time?

    Hi
    How do I determine the latency time?
    I need to connect 3 CAN nodes onto the CAN bus and need to know how to determine the delay(latency) time needed between the transmission of a message from one node and reception at the other,
    The latency time and Bandwidth both play a role in the transmission, right?
    Thanks
    Ekta

    Hi Ekta,
    The software you need if you are using an NI board is NI-CAN, and you can look at the driver download page for the appropriate version for your operating system. I'll suggest you take a look at the example programs that install with that driver to get you started. If you are developing using LabVIEW or LabWindows/CVI, go to Help>>Find Examples>>Hardware Input and Output>>CAN for examples. If you are using Visual Basic or C, go to ...\National Instruments\NI-CAN for examples. I have also attached a LabVIEW example below that shows how to enable self reception.
    If you are using another vendor's CAN board, you will need to install their driver, and see if they have any examples to get you started. I assume the approach for measuring the latency will be similar to what I suggested. Hope this helps. Goodluck!
    Regards,
    Message Edited by _Belle on 04-28-2006 07:42 AM
    Ebele O.
    National Instruments
    Attachments:
    Self_Reception.vi ‏97 KB

  • How to get previous row of result set in select query?

    I want to access the previous row of an result set obtained yet, in the same selectquery .
    How can I do that?

    Use analytical functions.
    For example:
    create table top_n_test (
       a number,
       b varchar2(10)
    insert into top_n_test values (1,   'one');
    insert into top_n_test values (2,   'two');
    insert into top_n_test values (3, 'three');
    insert into top_n_test values (4,  'four');
    insert into top_n_test values (5,  'five');
    insert into top_n_test values (6,   'six');
    insert into top_n_test values (7, 'seven');
    insert into top_n_test values (8, 'eight');
    insert into top_n_test values (9,  'nine');
    commit;
    select a, b from (
      select
        a,b,
        rank() over (order by b) r
      from
        top_n_test
    where
      r<4;
             A B
             8 eight
             5 five
             4 fourHTH
    Ghulam

  • What is the Cube refresh and how to determine cube refresh time for a cube

    hi,
    what will be the meaning of cube refershing, i believe it is clearing and updating the data in production weekly or monthly basis. how it will happen in general, do we need to do mannually, will there be any scheduler in production.
    please clarify me how to determine refresh timime for a cube, what facters we need to consider.
    Thanks,
    bhavani.

    I can't give you specific guidelines as every client/cube is different based on needs. Here is some general info.
    Cube refresh is a pretty generic name for a number of things.
    It could be as you say clearing and updating the cube, or just updating, or running calculations or running restructure operations. It's pretty much what you need it to be for your environment. As to timing, There are two timings to consider. First, the frequency of refresh. Is it Monthly, weekly, Daily, hourly? That depends on the application and the needs of the users. The second thing is how long the refresh takes. Is it seconds, minutes, hours, etc. This has to be considered to meed the User's SLA and hopfully fit into a batch processing window. Refreshes can be done manually or automated with batch or shell scripts (depending on the OS) and scheduled through whatever scheduling package is on the box (Windows AT scheduler, Cron, third party, etc)

  • How to Add extra data in result set of cfquerry?

    hi all,
    I am new to cold fusion please help me
    i am using the cfquery tag for executing a select query and getting the system name and system is from that........
    But i want an extra system name and system id to add to the result of that query with out changing the data base ..............
    please any one suggest me ...........IT's URGENT
    Thanks in advance
    Sudheer

    You'll have to use an array and the function queryAddColumn. An example follows.
    Suppose I have a result set called myQuery. There are 5 rows in it. I wish to add 2 new columns to the query, on the fly. The column names are username(type varchar) and userID(type integer)
    <!--- Create array corresponding to column username--->
    <cfset usernameArray = ArrayNew(1)>
    <cfset usernameArray[1] = "[email protected]">
    <cfset usernameArray[2] = "[email protected]">
    <cfset usernameArray[3] = "[email protected]">
    <cfset usernameArray[4] = "[email protected]">
    <cfset usernameArray[5] = "[email protected]">
    <!---
    The next line adds the new column, username, to the query. That's it. Done.
    The array indices correspond to the row numbers in the query.
    The function queryAddColumn returns the column number for the newly added column
    (in case you'll need it, which you usually wont ).
    --->
    <cfset columnNumber = queryAddColumn(myQuery, "username", "VarChar", usernameArray)>
    <!--- Now, do the same for the next new column, userID  --->
    <cfset userIDArray = ArrayNew(1)>
    <cfset userIDArray[1] = "23">
    <cfset userIDArray[2] = "121">
    <cfset userIDArray[3] = "9">
    <cfset userIDArray[4] = "76">
    <cfset userIDArray[5] = "44">
    <cfset columnNumber = queryAddColumn(myQuery, "userID", "integer", userIDArray)>

  • [Help] - How to create BP many times.

    Dear all,
    Pls help..
    i created Business Partners(BP) many times (use FM: COM_BPUS_BUPA_CREATE)
    This is the code:
    LOOP AT lt_mstcust INTO ls_mstcust.
    i FILL data cust that want to be created.
      CALL FUNCTION 'COM_BPUS_BUPA_CREATE'
        EXPORTING
          IV_PARTNERCATEGORY         = partner_cat
          IV_BUSINESSPARTNERGROUP    = lv_bpgroup
          IS_CENTRALDATA             = ls_central
          IS_CENTRALDATAORGANIZATION = ls_organ
          IS_ADDRESSDATA             = ls_address
          IV_ACCEPT_ERROR            = 'X'
          IV_BUSINESSPARTNERROLE     = lv_bprole
        IMPORTING
          EV_BUSINESSPARTNER         = lv_bpnumber
        TABLES
          IT_TELEFONDATA             = lt_telephone
          IT_FAXDATA                 = lt_fax
          ET_RETURN                  = lt_return.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT   = ''
          IMPORTING
            RETURN = lt_return.
    ENDLOOP. 
    end of code.
    The strange problems:
      Not all BP that i created saved in table BUT000, although all BP number was generated after running that FM.
      So i can say after i run the LOOP, i got all bp number. BUT, some of bp numbers were not found in table BUT000. It means when i run TCODE: BP and i entered BP number that were not found in BUT000, error message (bp is not found) would be raised.
    Do u have any solutions for it?
    Or are there others creating BP FM that can be run in LOOP (can create BP in many times)?
    Please help y..
    Ur help is very important for me.
    Regards.
    Daniel N.

    Hi Daniel,
    You can try out one of the following.
    1. Call the function module "COM_BPUS_INPUTDATA_CHECK" before the function module "COM_BPUS_BUPA_CREATE"
    2. Instead of calling the function module "COM_BPUS_BUPA_CREATE" Try calling "BAPI_BUPA_CREATE_FROM_DATA" and then commit and then call "COM_BPUS_BUPA_ROLE_ADD"
    3. Try removing the flag IV_ACCEPT_ERROR = 'X' from the function module call.
    4. In the BAPI_TRANSACTION_COMMIT pass a value 'X' to the parameter WAIT.
    Let me know if this helps!
    Jash.

  • How to create a browsable, distributable result set?

    I want do develop a web application, which must be able to browse (previous page, next page) in large result sets. The web application is distributed on several servers (persistent session). What is the way to handle this?

    The web application is distributed on
    several servers (persistent session). What is the way
    to handle this?Can you explain what a persistent session distributed on serveral servers means?

Maybe you are looking for

  • My Adobe LiveCycle Designer ES closes when I open it....:(

    Hello all, I want to thank you beforehand for the help regarding this matter. I use Windows Vista and my Adobe LiveCycle Designer was working before but for the last week and a half or so I have not been able to get it to work! I have done scandisk/d

  • Will not restore or show up in iTunes?!

    Have recently upgraded iPhone 3 software to most recent and has backed up fine, but will not restore. The screen says connect to iTunes but will not be picked up on itunes at all, and will not show on my computer either ?!?!

  • Sap script (ABAP-HR)

    hi friends, plz give me the solution to the following, its urgent yar. in abap we are copy a script from client 000 and done the modification according to the requirement, thn we go for NACE in that we remove the standard script name and we give our

  • Global reference in J2EE

    is it possible for inter-clients (for example, java bean, ejb or servlet in J2EE) to get a global reference to an object which is in momory?

  • Can you import the graphic equalizer presets from 1.5 into 3.0?

    Is there a way to import the graphic equalizer presets from AA 1.5 into 3.0?  I want to use the "Destination: Car Stereo" preset.