Help with Time Period Query

Dear Forum,
I am trying to put together a SQL such that it lists my Invoices in aging bucket depending upon when I run the report
For eg :
inv number , 0-1 , 1-2, 2-3 , 3-4 and so on months.
For given report run date and invoice date , it should put the inv in correct aging column
a) rpt run dt = 06-Jan-11
inv dt = 13-Dec-2010
aging column = 1-2 months
b) rpt run dt = 06-Jan-11
inv dt = 03-Jan-2011
aging column = 0-1 months
c) rpt run dt = 14-Feb-11
inv dt = 13-Dec-2010
aging column = 2-3 months
d) rpt run dt = 06-Feb-11
inv dt = 01-Feb-2011
aging column = 0-1 months
Basically, if the inv date is in same month as report run dt then its aging column - 0-1
Inv date beyond this is 1-2, 2-3 and so on.
I tried below but it doesn't work for case a) , b) ...
select invnum,inv_amt,
case
   when to_number(to_char(sysdate,'MM'))-to_number(to_char(invdate,'MM'))<1 then
    inv_amt
else
   0
end col_0_1,
case
when to_number(to_char(sysdate,'MM'))-to_number(to_char(invdate,'MM'))>=1 and to_number(to_char(sysdate,'MM'))-to_number(to_char(invdate,'MM'))<2
            then
   inv_amt
else
  0
end col_1_2
------ ..... and so on .
from
invoices_tab;Your help would be appreciated.
Thanks
Shankar

Hi,
As Maxim said, you can do that with built-in functions. For example:
SELECT     CASE
            WHEN  inv_dt >                      SYSDATE                     THEN 'Future'
         WHEN  inv_dt >=              TRUNC (SYSDATE, 'MONTH')       THEN  '0-1 Months'
         WHEN  inv_dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH'), -1)  THEN  '1-2 Months'
         WHEN  inv_dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH'), -6)  THEN  '2-6 Months'
                                                                          ELSE  'Over 6 Months'
     END     AS aging_bucket
,     ...If you're doing the exact same thing in several different statements, then you might want to write your own PL/SQL function. That will certainly be more convenient, but it will be slower than doing the whole job in SQL.

Similar Messages

  • SQL Help with Time Period vs Time Period  Comparison

    Hello,
    I am trying to create a query that will provide me a result set that will have current revenue (based off user selection of time) compared to another set of revenue with a different time period.
    For example:
    select a.xx_adm_adv_id, a.xx_edition, sum(a.xx_net_space)
    from ps_xx_adm_work_ord a
    where A.xx_issue = 'JAN'
    AND A.XX_ISSUE_YEAR = '2011'
    group by a.xx_adm_adv_id, a.xx_edition
    will provide my current data set, now I want to pull in the result set below, but in the 4th column based off of XX_ADM_ADV_ID & XX_EDITION (no repeats for these combinations).
    select B.xx_adm_adv_id, B.xx_edition, sum(B.xx_net_space)
    from ps_xx_adm_work_ord B
    where B.xx_issue in ('JUN', 'JUL')
    AND B.XX_ISSUE_YEAR = '2012'
    group by B.xx_adm_adv_id, B.xx_edition
    So essentially, I should be seeing all xx_adm_adv_id and xx_edition for both time periods and data in atleast one set of columns (3rd or 4th)
    I am running 10.2.0.4.0
    Many thanks in advance!

    Did you try the query that i provided?
    Commented XX_ISSUE_YEAR condition,adjust it to meet your requirements.
    SQL>
    SQL> select distinct a.xx_adm_adv_id,
      2         a.xx_edition,
      3         sum(case
      4               when xx_issue = 'JAN'-- and XX_ISSUE_YEAR = '2011'
      5                  then
      6                a.xx_net_space
      7               else
      8                0
      9             end) over(partition by a.xx_adm_adv_id, a.xx_edition),
    10         sum(case
    11               when xx_issue in ('JUN', 'JUL')-- and XX_ISSUE_YEAR = '2012'
    12                 then
    13                a.xx_net_space
    14               else
    15                0
    16             end) over(partition by a.xx_adm_adv_id, a.xx_edition)
    17    from PS_ORDER a
    18   where A.XX_ISSUE in ('JAN', 'JUN', 'JUL')
    19     --AND A.XX_ISSUE_YEAR in ('2011', '2012')
    20     order by a.xx_edition
    21  ;
    XX_ADM_ADV_ID XX_EDITION                     SUM(CASEWHENXX_ISSUE='JAN'--AN SUM(CASEWHENXX_ISSUEIN('JUN','
    000016004     NAT                                                    5722.2                         2861.1
    000016073     REG                                                   5111.12                              0
    000025008     REG                                                         0                        2665.32
    SQL>

  • New to Mac, Help with Time Machine! Partition External HDD or not?

    Hey Guys I'm a new mac user
    I need help with  time machine
    I wanted to know how time machine works and what all does it back up?
    I have 2 hard drives one is of 1TB and one is of 320gb
    In the 1TB hard drive i store all my music videos and work stuff it is windows formatted
    The 320gb hard drive is mac formatted and I was thinking of making a partition on it one with 250gb for time machine and the remaining 70 gb for mac softwares and files. The ssd of my mac has a capacity of 256gb. I have read for time machine you need at least 2x the space of your ssd on your external hard drive but i don't understand if my ssd is only 256 and can store files worth 256gb why do i need double the space? Secondly if I choose to use the complete 320 gb for time machine will that be okay or even if i choose to partition it to 250gb for time machine will that be fine too? Or will I need to format my 1TB hard disk out of which currently only 300 gb is empty and partition that to 500 gb for time machine?
    I'm really confused every tells me to use time machine but do I need it? And what does it exactly do?
    Your input will be really appreciate thanks

    The reason that you want a partition (or drive) of 2-3 times the size of your boot drive for Time Machine is so that you can keep backups further back than just the current boot drive state - for that you'd need to make a clone of the drive rather than using Time Machine (see -> http://pondini.org/TM/Clones.html).
    For more information for backups in general, see -> Most commonly used backup methods.
    Note that you can't use Time Machine to backup a Windows partition.
    Good luck,
    Clinton
    MacBook Pro (15” Late 2011), OS X 10.??, 16GB Crucial RAM, 960GB M500 Crucial SSD, 27” Apple Thunderbolt Display

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Help with a BEx Query

    Hello Gurus,
    I have a requirement to write a query to list all the customers who have purchased over $450 (customer total) for a three month period and had not purchased any product from an item category in the same time period. My users want to see the sold_to_party’s. I am using an Invoice ODS.
    I have basically created two queries, the first one with 0BILL_DATE in the filter and restricted to three months period, 0SOLD_TO in the rows and 0NETVAL_INV in the Columns and set a condition with value greater than $450. In the second query, included 0SOLD_TO in the rows and created a variable for the sold_to_party and included the first query with processing by 'Replacement path' and placed item category (0ITEM_CATEG) in the filter and restricted to an item category and placed the 0NETVAL_INV in the columns area and created a condition with value equal to zeros.
    This is not giving me any sold_to_party listing. I think it is because in the second query, it is trying to read zero invoice value, which does not exist in the ODS.
    Then I tried creating an Infoset with this ODS and 0SOLD_TO master data and used left outer join. This also does not give me the desired result.
    Can somebody help me how to achieve this? Your help will be greatly appreciated.
    Thanks

    Hi,
    <i>In the second query, included 0SOLD_TO in the rows and created a variable for the sold_to_party and included the first query with processing by 'Replacement path' and placed item category (0ITEM_CATEG) in the filter and restricted to an item category and placed the 0NETVAL_INV in the columns area and created a condition with value equal to zeros.</i>
    Yes the above always brings the  zero reows in the second report. becuase you are picking the custoemrs from first query (i.e who has sales ) and in the condition your mentioning to display no sales Customers.
    Solution:
    1) Make 0SOLD_TO as data target.
    2) Create the Multi provider on Invoice ODS and 0sold_to
    3) you need to have  1 resstricted Column(say Col1) and one normal column(0NETVAL_INV) say col2.
    4) you need to have  2 conditions
    5) In restriction column: Drag and drop 0NETVAL_INV and restrict it with  0ITEM_CATEG = 'your item category).
    6) 0BILL_DATE in the filter and restricted to three months period
    7) 1 st condition: col1 <> 0.
    2nd condition col2 = 0.
    So in single report you can display the user asked information.
    With rgds,
    Anil Kumar sharma .P

  • Help with Inner Join query in SQL

    Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
    My table structure is :
    table_packages
    packageID
    package
    packageDetails
    etc
    table_destinations
    destinationID
    destination
    destinationDetails
    etc
    table_packagedestinations
    packageID
    destinationID
    ..so nothing that complicated.
    So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
    So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
    This is the PHP from the header, including my INNER JOIN query....
    PHP Code:
    <?php
    $ParampackageID_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    $ParamSessionpackageID_WADApackages = "-1";
    if (isset($_SESSION['WADA_Insert_packages'])) {
      $ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
    $ParampackageID2_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    mysql_select_db($database_connPackages, $connPackages);
    $query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
    $WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
    $row_WADApackages = mysql_fetch_assoc($WADApackages);
    $totalRows_WADApackages = mysql_num_rows($WADApackages);
    $colname_educationalDestinations = "1";
    if (isset($_GET['PackageID'])) {
      $colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
    mysql_select_db($database_connPackages, $connPackages);
    $query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
    $educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
    $row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
    $totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
    ?>
    And where I'm trying to display the destinations themselves, I have : 
    <table>
            <tr>
                     <td>Destinations :</td>
                </tr>
               <?php do { ?>
            <tr>
                 <td><?php echo $row_educationalDestinations['destination']; ?></td>
            </tr>
            <?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
    </table>
    If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working. 
    Thanks.

    First off, you need to get the database tables so that there is a relationship between them.
    In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
    table_packages
    packageID
    package
    packageDetails
    destination
    destinationDetails
    etc
    If there is a one to many relationship, then the following would be true
    packages
    packageID
    package
    packageDetails
    etc
    destinations
    destinationID
    packageID
    destination
    destinationDetails
    etc
    The above assumes that there are many destinations to one package with the relationship coloured orange.
    Once you have the above correct you can apply your query as follows
    SELECT *
    FROM packages
    INNER JOIN destinations
    ON packages.packageID = destinations.packageID
    WHERE packages.packageID = %s
    ORDER BY destination ASC
    The above query will show all packages with relevant destinations

  • Help with Time Machine Backups not working..

    Let me preface this by saying I have spent the last day scouring the internet for solutions to my problem. I have tried every option that I have run across and have had no luck in resolving my problem. As a last resort, I'm turning here in hopes that you can be of help.
    I have a 2012 Macbook Pro running Moutain Lion.  I use an external HD for my time machine backups.  I am having an issue with Time Machine not functioning.  The initial error message I receive when I attempt to use TM to backup is:  "Time machine couldn't coplete the backup to Rick's backup disk". "Unable to complete backup. an error occurred while creating the backup folder".
    I searched the forums and net and found several things to do to try and resolve this issue.  My computer will freeze out and not let me erase, or re-partition the the hard drive, so I switched it over to an older macbook of my girlfriends and am successfully able to erase, and re-partition the drive (using disk utility) as suggested by several forum postings I have read.  I am able to run disk verify and disk repair and both say the disk is "ok" with no issues.  The moment the erase and partition is done, her computer prompts a message : "Would you like to use this disk for Time Machine Backups" which tells me it is working properly.  When I move it back to my macbook pro and attempt to run TM backup, it will now work and copy about 10g of my 120g before shutting down with this error message:
    "Time Machine couldn't complete the backup to "Rick's Backup Disk".  An error occurred while copying files. The problem may be temporary. If the problem persists, use disk utility to repair your backup disk."
    If i attempt to re-run TM at that point, I get the original error message:
    "Time machine couldn't coplete the backup to Rick's backup disk". "Unable to complete backup. an error occurred while creating the backup folder".
    If I move the TM back to my Girlfriends computer and attempt to run TM, it will function properly and backup her entire harddrive.  When I erase and try again on mine, I always end up back with the same issues.  It's clearly something in my macbook that is screwing it up.  Can anyone please offer some help! I'd be much appreciative. 

    rcury4 wrote:
    "Time machine couldn't coplete the backup to Rick's backup disk". "Unable to complete backup. an error occurred while creating the backup folder".
    See #C10 in Time Machine - Troubleshooting
    "Time Machine couldn't complete the backup to "Rick's Backup Disk".  An error occurred while copying files. The problem may be temporary. If the problem persists, use disk utility to repair your backup disk."
    Not one of Apple's more informative messages. 
    There's a problem with a file on your system.  See #C3 in the above link. It will show you how to locate the message(s) that describe the problem, then help you fix it.    If that doesn't help, post back with details, including all the messages, what you've done, and the results.

  • Need help with LikeFilter for querying the keyset instead of value

    Hi,
    I'm looking for help with the LikeFilter.
    I need to query the cache to get all entries with key starting with a particular string.
    I could see samples using LikeFilter for querying the values in the cache but not the keyset.
    Can someone help?
    E.g:
    Cache Entries:
    abc123 - value1
    abc234 - value2
    bcd123 - value3
    I want to get all entries with key starting with 'abc'.
    thanks,
    rama.

    NJ, thanks for the quick reply.
    I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
    KeyExtractor extractor = new KeyExtractor("getKey");
    Filter filter = new LikeFilter(extractor, id+":%",'-',false);
    -rama.
    Edited by: 911950 on Feb 2, 2012 1:18 PM

  • Help with a PowerPivot query

    Hi,
    I've got a server audit log in PowerPivot (114,000 rows) which I provide some basic reporting from (PowerPivot is not my specialist subject so go easy).  What I now need to perform a Distinct filter, but can't get the logic right. Basically the log
    as two bits of information, 1) is the source of the job and 2) if it was a success or failure.    What I need to do is to find all of the Source items that have never completed sucessfully.  Any ideas on what formula is best to use, or
    do I need to split in to multiple sheets and create a table relationship?
    Source,Status
    ======,======
    Source1,Fail
    Source1,Fail
    Source1,Success
    Source2,Fail
    Source3,Fail
    Source3,Success
    So in the above example, I would only expect the filter to show me Source2
    Thanks
    Alex

    Hi Alex,
    using Power Query instead, it would work like this:
    Once you've pushed your table to PQ, add a column "helper" with value=1.
    Then pivot on "Status", taking "helper"-column into "values column"
    (hope translation is understandable, as I'm using localized Version & translation via "Quick info" isn't working in the PQ menu)
    Then filter on column "Success" = blank.
    Imke

  • Help with a group query

    I have the following table
    EX_ID
    EX_NAME
    EX_SURNAME
    EX_FLAG
    1
    TOM
    JONES
    Y
    1
    JIM
    SLIM
    N
    1
    BO
    SELECTA
    Y
    2
    AIRES
    BEARS
    N
    2
    JIM
    DAVIES
    Y
    3
    PAUL
    BALL
    N
    3
    YOU
    KNOW
    N
    I need to create a query that only displays one of the ex_id’s, it doesn’t matter which one.  When the query has been run it will look like below:
    EX_ID
    EX_NAME
    EX_SURNAME
    EX_FLAG
    1
    TOM
    JONES
    Y
    2
    AIRES
    BEARS
    N
    3
    YOU
    KNOW
    N
    Can anyone help with this query?

    SELECT * FROM
    SELECT *,ROW_NUMBER () OVER (PARTITION BY ex_id ORDER BY (SELECT 0))
    FROM tbl
    ) AS Der WHERE rn=1
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Help with the problem query

    Hi,
    I have another query running slow when executed from cognos. It is also not returning any output continues to execute,
    with "Union15" as (
    select distinct CASE WHEN(substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4)||case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", "EES_ENERGY_MASTER"."PAT_KEY" "Cases_Using_Energy", 0 "Total_Cases"
    from "MDM_DBA"."EES_ENERGY_MASTER" "EES_ENERGY_MASTER", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV"
    where "EES_ENERGY_MASTER"."DISC_MON">=2006101 and "EES_ENERGY_MASTER"."PDCT_CAT"='Energy' and substr("EES_ENERGY_MASTER"."ICD_CODE", 1, 2)='68-gyn' and "EES_ENERGY_MASTER"."MANUFACTURER"='EES' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID" union 
    select CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", 0 "Cases_Using_Energy", count("MVW_EES_ICD_STATS"."CASES") "Total_Cases"
    from "MDM_DBA"."MVW_EES_ICD_STATS" "MVW_EES_ICD_STATS", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV", "MDM_DBA"."EES_HOSP_CHG_PROV" "EES_HOSP_CHG_PROV"
    where "MVW_EES_ICD_STATS"."DISC_QTR">=20061 and "MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' and "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES' and "MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID" and "MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID"
    group by CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end  IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END)
    select "T1"."C0" "levelkey", "T1"."C1" "Cases_Using_Energy", "T0"."C0" "Cases_Using_Energy1", "T1"."C2" "Total_Cases"
    from (
    select count(distinct "Union15"."Cases_Using_Energy") "C0"
    from "Union15") "T0", (
    select "Union15"."QUARTER" "C0", count(distinct "Union15"."Cases_Using_Energy") "C1", sum("Union15"."Total_Cases") "C2"
    from "Union15"
    group by "Union15"."QUARTER") "T1"The explain plan is as follows,
    PLAN_TABLE_OUTPUT
    | Id  | Operation                             |  Name                        | Rows  | Bytes |TempSpc| Cost  |
    |   0 | SELECT STATEMENT                      |                              |     1 |    50 |       |    22 |
    |   2 |  TEMP TABLE TRANSFORMATION            |                              |       |       |       |       |
    |   1 |   RECURSIVE EXECUTION                 | SYS_LE_2_0                   |       |       |       |       |
    |   0 |    INSERT STATEMENT                   |                              |  3053 |   128K|       |  1372 |
    |   1 |     LOAD AS SELECT                    |                              |       |       |       |       |
    |   2 |      SORT UNIQUE                      |                              |  3053 |   128K|   376K|  1372 |
    |   3 |       UNION-ALL                       |                              |       |       |       |       |
    |*  4 |        HASH JOIN                      |                              |  3052 |   128K|       |   185 |
    |*  5 |         TABLE ACCESS FULL             | EES_CONS_PROV                |   622 |  3732 |       |     2 |
    |*  6 |         TABLE ACCESS BY INDEX ROWID   | EES_ENERGY_MASTER            |  3055 |   110K|       |   182 |
    |*  7 |          INDEX RANGE SCAN             | IDX_ENERGY_PDCT_CAT          |  1978 |       |       |  2478 |
    |   8 |        SORT GROUP BY                  |                              |     1 |    40 |       |  1160 |
    |*  9 |         TABLE ACCESS BY INDEX ROWID   | EES_HOSP_CHG_PROV            |     4 |    72 |       |     1 |
    |  10 |          NESTED LOOPS                 |                              |     1 |    40 |       |  1157 |
    |  11 |           NESTED LOOPS                |                              |     1 |    22 |       |  1156 |
    |* 12 |            TABLE ACCESS BY INDEX ROWID| MVW_EES_ICD_STATS            |     1 |    16 |       |  1155 |
    |* 13 |             INDEX RANGE SCAN          | MVWICDSTATS_DISCQTR_IDX      |    13M|       |       | 26068 |
    |* 14 |            TABLE ACCESS BY INDEX ROWID| EES_CONS_PROV                |     1 |     6 |       |     1 |
    |* 15 |             INDEX UNIQUE SCAN         | EES_CONS_PROV_PK             |     1 |       |       |       |
    |* 16 |           INDEX RANGE SCAN            | PROV_ID_IDX_2                |    65 |       |       |     1 |
    |   3 |   MERGE JOIN CARTESIAN                |                              |     1 |    50 |       |    22 |
    |   4 |    VIEW                               |                              |     1 |    13 |       |     3 |
    |   5 |     SORT GROUP BY                     |                              |     1 |    13 |       |       |
    |   6 |      VIEW                             |                              |  3053 | 39689 |       |     3 |
    |   7 |       TABLE ACCESS FULL               | SYS_TEMP_0FD9D68B3_C112F95D  |  3053 |   110K|       |     3 |
    |   8 |    VIEW                               |                              |     1 |    37 |       |    19 |
    |   9 |     SORT GROUP BY                     |                              |     1 |    37 |       |    19 |
    |  10 |      VIEW                             |                              |  3053 |   110K|       |     3 |
    |  11 |       TABLE ACCESS FULL               | SYS_TEMP_0FD9D68B3_C112F95D  |  3053 |   110K|       |     3 |
    Predicate Information (identified by operation id):
       4 - access("EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
       5 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
       6 - filter("EES_ENERGY_MASTER"."DISC_MON">=2006101 AND SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2)='68-gyn'
                  AND "EES_ENERGY_MASTER"."MANUFACTURER"='EES')
       7 - access("EES_ENERGY_MASTER"."PDCT_CAT"='Energy')
       9 - filter("EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' AND "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES')
      12 - filter("MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn')
      13 - access("MVW_EES_ICD_STATS"."DISC_QTR">=20061 AND "MVW_EES_ICD_STATS"."DISC_QTR" IS NOT NULL)
      14 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
      15 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
      16 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID")
    Please help with some solution.

    OK: the third parameter of the SUBSTR function indicates the (maximum) length of the returnd string.
    Therefore SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2) could possibly be '68' , but never '68-gyn'.
    '68-gyn' is just 4 characters too long.
    Urs

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Help with Time Evaluation and function exit (HRPTIM03 / SAPLHRLV_001)

    Hello,
    Hopefully someone can help me with an issue I am having with time evaluation and a user exit I wrote.  The code for my exit is at the end of this post.  IN DEV and QAS, everything works.  However, in PRD, multiple rules are considered fulfilled (when looking in PT60), and so employees get two sets of vacation entitlements per month.
    We have three rules for quota type 03 (vacation).  Rules 3,6, and 9.  Only rule 9 should apply to the individuals with the two job numbers in the code.
    Any help would be greatly appreciated.
    Shane
    WHEN ABSENCE QUOTA TYPE IS 3 (VACATION)
    CASE XT559L-QTYPE.
    WHEN '3'.
    CASE - COMPARE SELECTION RULE FOR ABSENCE QUOTA TYPES
      CASE XT559L-ACCNR.
    WHEN RULE SELECTED IS 009
        WHEN '9'.
        IF JOB NUMBER IS 5084 OR 3084, THEN THE RULE APPLIES
          IF XP0001-STELL = '5084' OR XP0001-STELL = '3084'.
            XSUBRC = '0'.
        OTHERWISE, THE RULE DOES NOT APPLY
          ELSE.
            XSUBRC = '1'.
          ENDIF.
    WHEN ANY OTHER RULE IS SELECTED
        WHEN OTHERS.
        IF JOB NUMBER IS 5084 OR 3084, THEN THE RULE DOES NOT APPLY
          IF XP0001-STELL = '5084' OR XP0001-STELL = '3084'.
            XSUBRC = '1'.
        OTHERWISE, THE RULE APPLIES NORMALLY
          ELSE.
            XSUBRC = '0'.
          ENDIF.
      ENDCASE.
    WHEN OTHERS.
    ENDCASE.

    The problem was that even though the code was transported to PRD, and listed as Active - it still was not activated, and had to manually be done though CMOD.

Maybe you are looking for

  • Capture HD video in Final Cut Express with a Sony HDR-FX7

    When try to capture a video from my new Sony HDR-FX7 using the HD Format Apple Intermediate Codec 1080i60 the preview screen never shows the video being captured. In fact the video is never captured. Any suggestions to how set the 'Easy Setup'? When

  • Do transport acknowledgement work for HTTP ?

    hi all, I'm posting an HTTP in a BPM scenario.I've put mode as transport in send step. However in SXMB_moni its showing,ack not possible. I've searched and it seems ack is possible for HTTP. can anyone tell why i am getting the error?

  • Create a Job for a transaction dynamically through ABAP program.

    Hello Experts, Can a job be created for a transaction dynamically, say for example i have a parameter on selection screen which will take the name of the transaction and then i have to create a job to run that transcation. Plz provide sample code. Re

  • How to enlarge pictures and change reading view

    I've bought an ebook which should contain large Excel screenshots and text. According to the description it should be in 2 columns, one for text and one for screenshots. I can see the text and enlarge it, but the screenshot pictures are very small an

  • Incomming Payment (payment means) default?

    hello, i want to change the default G/L Account in the Payment Means Window in the incoming payment, (see image attached) http://i264.photobucket.com/albums/ii184/abing430/IncommingPayment.jpg thank you in advance..... FIDEL