Date Range  - Delete ZERO Values

Hi All,
     Few days back I had posted Query  Regarding  Date range  where in I enter Proj# from_month, from_year, To_month and To_year.
The output data for the project must be within this year range.
suppose I enter proj no. 13381 and
from_month - 05
from_year - 2004
To_month - 04
from_year - 2005
This is the Desired Output:
yearmonth                            plan14
200406 -
13381 -
100
200407 -
13381 -
100
200409 -
13381 -
678
Right Now the Output what Iam getting is:
yearmonth                            plan14
200405 -
13381 -
0
200406 -
13381 -
100
200407 -
13381 -
100
200408 -
13381 -
0
200409 -
13381 -
678
I  Just  want the NON ZERO  PLan14 values.  The PLan14 values  with '0'  should  be deleted .
Below  is the Jist of the code.
RANGES: S_GJAHR FOR COSP-GJAHR,
        R_YEAR  FOR COSP-GJAHR,
        R_DATE  FOR PROJ-ERDAT,
        R_MONTH FOR CKML1-POPER,
        S_OBJNR FOR COSP-OBJNR,
        S_KSTAR FOR COSP-KSTAR.
DATA: MNT_INDX(20)     TYPE C,
      HLD_INDX(3)      TYPE N.
DATA:  W_MTH(2) TYPE N,
       W_DATE  LIKE PROJ-ERDAT.
DATA: BEGIN OF ITAB_OUT_TYPE,
        PERIOD(10)       TYPE C,
        PROJDEF(20)          TYPE C,
        PROJ_TITLE(20)        TYPE C,
        STATUS(20)            TYPE C,
        PROJECT_TYPE(20)      TYPE C,
        START_DATE(20)        TYPE C,
        FINISH_DATE(20)      TYPE C,
        CONTRACT(20)          TYPE C,
        CLIENT(20)            TYPE C,
        PLAN14(25)       TYPE  C,
        END OF ITAB_OUT_TYPE.
DATA ITAB_OUT LIKE ITAB_OUT_TYPE OCCURS 10 WITH HEADER LINE.
FIELD-SYMBOLS <FS>.
PARAMETERS FR_MONTH(2) TYPE N OBLIGATORY.
PARAMETERS FR_YEAR(4) TYPE N OBLIGATORY.
PARAMETERS TO_MONTH(2) TYPE N .
PARAMETERS TO_YEAR(4) TYPE N .
DATA: W_TXT(20)     TYPE C.
  R_YEAR-LOW = FR_YEAR.
  R_YEAR-HIGH = TO_YEAR .
  R_YEAR-OPTION = 'BT'.
  R_YEAR-SIGN = 'I'.
APPEND R_YEAR.
concatenate FR_YEAR FR_MONTH  INTO R_DATE-LOW .
  concatenate TO_YEAR TO_MONTH  INTO R_DATE-HIGH.
  R_DATE-OPTION = 'BT'.
  R_DATE-SIGN = 'I'.
  APPEND R_DATE.
SELECT * FROM COSP
             WHERE OBJNR = PRPS-OBJNR    AND
              GJAHR IN R_YEAR     AND
     KSTAR BETWEEN '0000400996'    AND '0000400999' AND
      VERSN = '014'                               AND
      WRTTP = '01' .
      DO 12 TIMES.
        W_MTH = SY-INDEX.
        CONCATENATE COSP-GJAHR W_MTH  INTO W_DATE.
        CHECK W_DATE IN R_DATE.
        PERFORM CONVERT-DATE1 USING W_DATE.
        MOVE HOLDDATE1  TO ITAB_OUT-PERIOD.
        HLD_INDX = SY-INDEX.
        CONCATENATE 'COSP-WKG' HLD_INDX INTO W_TXT.
       ASSIGN (W_TXT) TO <FS>.
    CLEAR ITAB_OUT-PLAN14.
    ITAB_OUT-PLAN14 = ITAB_OUT-PLAN14 + <FS>.
APPEND ITAB_OUT.
enddo.
ENDSELECT.
I need  all positive values  of  the month  that are in the range.   The Zero values  must be deleted .  How  can i do that.  PLease  do let me  know.
Thanks in advance
Dan

You can do this easily just by deleting all records in one shot.
delete ITAB_OUT where plan14 = 0.
You can put that statement after the SELECT...ENDSELECT.
Or you can not even add them to the internal table at all.  You can check before you APPEND to the table.
CLEAR ITAB_OUT-PLAN14.
ITAB_OUT-PLAN14 = ITAB_OUT-PLAN14 + <FS>.
<b>If itab_out-plan14 > 0.
APPEND ITAB_OUT.
endif.</b>
enddo.
ENDSELECT.
Regards,
Rich Heilman

Similar Messages

  • Date range as variable values in report selection

    On a report selection screen, how can we save range values as variant?
    For example, S_ALR_87012341, I want to save the values of from- and to- dates for posting date using dynamic date calculation as selection parameter. 
    From date:  current date u2013 365 days
    To date:  current date
    I can only put one value at a time but not both.  Any value I input to the Name of Variable field, it is populated as a from-date value
    How can we put both names of variable for the from- and to- dates to the variant attributes?

    Hi,
    For the example you gave, choose Variable 'Current date - xxx,current date + yyy' , enter 365 and 0 for xxx and yyy and save the variant. When you call up that variant, you will see both 'From' and 'to' are populated.
    Regards,
    Ming

  • Delete zero value keyfigure (volume)

    Hi,
    This is for BW3.5 BPS.
    I would like to see the list of records which has volume = 0.
    What is happening now...
    already( last yr) we deleted few records (material A, sold to A), so the volume become zero, if some user try to add record  ( same as the deleted records) this yr, error shows that the record already exists.
    Is there anyway I can add volume to the records which is zero now.
    Note: if the key figure value is zero those records are not displayed in the layout.
    Thanks
    Billy

    <FONT FACE = "Tahoma", Font Color = "Blue">
    Hi<br>
    I am very surprised to see this. Because a cube can have multiple records with same characteristic key combination but different/same key figure values. Then based on the Aggregation behaviour defined in the key figure definition, system should add records or do the necessary action.<br><br>
    Can you please compress your InfoCube with ZERO ELIMINATION tick mark selected? This should solve your problem, I think.
    <br><br>
    Hope it helps.<br>
    Cheers Abhijit</FONT><FONT FACE = "Verdana", Font Color = "Red">
    REMOVED
    </FONT>

  • Date Range and Null Values

    Post Author: mrae
    CA Forum: Formula
    I want to pull up data that have been completed for the month, but also want to include null values.  I did the following but didn't work.
    (isnull({wrhwr.date_completed}) or {wrhwr.date_completed} => 4/1/2008 12:00:00AM or =<4/30/2008 11:59:59PM
    Help, please?

    Post Author: SKodidine
    CA Forum: Formula
    Try:
    isnull({wrhwr.date_completed}) or {wrhwr.date_completed} IN datetime(2008,04,01,00,00,00) to datetime(2008,04,30,23,59,59)

  • Stacked 100% bar chart - Problem with datatips for zero value data points

    I have a stacked 100% bar chart that shows datatips in Flex 4.   However, I don't want it to show datatips for
    data points with zero values.   Flex 4 shows the datatip for a zero value data point on the left side of a bar if the data point is not the first in the series.
    Here's the code that illustrates this problem.    Of particular concern is the July bar.    Because of the zero value data point problem, it's not possible to see the datatip for "aaa".
    Any ideas on how we can hide/remove the datatips for zero value data points ?        Thanks.
    <?xml version="1.0"?>
    <s:Application
    xmlns:fx="
    http://ns.adobe.com/mxml/2009"xmlns:mx="
    library://ns.adobe.com/flex/mx"xmlns:s="
    library://ns.adobe.com/flex/spark"creationComplete="initApp()"
    height="
    1050" width="600">
    <s:layout>
    <s:VerticalLayout/>
    </s:layout>
    <fx:Script><![CDATA[ 
    import mx.collections.ArrayCollection;[
    Bindable] 
    private var yearlyData:ArrayCollection = new ArrayCollection([{month:
    "Aug", a:1, b:10, c:1, d:10, e:0},{month:
    "July", a:1, b:10, c:10, d:10, e:0},{month:
    "June", a:10, b:10, c:10, d:10, e:0},{month:
    "May", a:10, b:10, c:10, d:0, e:10},{month:
    "April", a:10, b:10, c:0, d:10, e:10},{month:
    "March", a:10, b:0, c:10, d:10, e:10},{month:
    "February", a:0, b:10, c:10, d:10, e:10},{month:
    "January", a:10, b:10, c:10, d:10, e:10}]);
    private function initApp():void {}
    ]]>
    </fx:Script>
    <s:Panel title="Stacked Bar Chart - Problems with DataTips for Zero Value Items" id="panel1">
    <s:layout>
    <s:HorizontalLayout/>
    </s:layout>
    <mx:BarChart id="myChart" type="stacked"dataProvider="
    {yearlyData}" showDataTips="true">
    <mx:verticalAxis>
     <mx:CategoryAxis categoryField="month"/>
     </mx:verticalAxis>
     <mx:series>
     <mx:BarSeries
    xField="a"displayName="
    aaa"/>
     <mx:BarSeries
    xField="b"displayName="
    bbb"/>
     <mx:BarSeries
    xField="c"displayName="
    ccc"/>
     <mx:BarSeries
    xField="d"displayName="
    ddd"/>
     <mx:BarSeries
    xField="e"displayName="
    eee"/>
     </mx:series>
     </mx:BarChart>
     <mx:Legend dataProvider="{myChart}"/>
     </s:Panel>
     <s:RichText width="700">
     <s:br></s:br>
     <s:p fontWeight="bold">The problem:</s:p>
     <s:p>Datatips for zero value data points appear on left side of bar (if data point is not the first point in series).</s:p>
     <s:br></s:br>
     <s:p fontWeight="bold">For example:</s:p>
     <s:p>1) For "June", eee = 0, mouse over the left side of the bar to see a datatip for "eee". Not good.</s:p>
     <s:br></s:br>
     <s:p>2) For "July", eee = 0 and aaa = 1, can't see the datatip for "aaa", instead "eee" shows. Real bad.</s:p>
     <s:br></s:br>
     <s:p>3) For "Feb", aaa = 0, datatip for "aaa" (first point) does not show. This is good.</s:p>
     <s:br></s:br>
     <s:p>4) For "Mar", bbb = 0, datatip for "bbb" shows on the left side of the bar. Not good.</s:p>
     <s:br></s:br>
     <s:p fontWeight="bold">Challenge:</s:p>
     <s:p>How can we hide/remove datatips for zero value data points?</s:p>
     <s:br></s:br>
     </s:RichText></s:Application>

    FYI.
    Still have the issue after upgrading to the latest Flex Builder 4.0.1 with SDK 4.1.0 build 16076.   
    Posted this as a bug in the Adobe Flex Bug and Issue Management system.     JIRA
    http://bugs.adobe.com/jira/browse/FLEXDMV-2478
    Which is a clone of a similar issue with Flex 3 ...
    http://bugs.adobe.com/jira/browse/FLEXDMV-1984

  • Same date range values

    Hi Experts,
    I have a complex requirement for a date range functionality.
    Here is the detailed explanation:
    I have field TransactionDate field coming from an Oracle View.
    I have 2 parameters to be created on the same field and either of them can be selected but not both and both can be blank even.
    1. Transaction date on or before
    2. Transaction Date Range
    We may have values for only one prompt at any given point.
    If the user enters value for Transaction date on or before, then report should display data less than or equal to the date entered.
    If the user enters values for the Transaction Date Range, report should display date between the user entered dates.
    If none is entered report should display data for all dates.
    Now, when the Transaction Date Range has same values in Start of Range and End of Range, we need to display the record for maximum(Transaction Date) under a particular account, irrespective of the dates specified, i.e if the user enters current date in Start of Range and End of Range and there will be no records for this date. In this scenario, report should display the maximum(Transaction Date) for that account.
    I've tried all of I could, but ending up with a blank report.
    Any suggestions will be of great help. Thanks in advance.
    Naresh

    HI Naresh,
    Have you tried this,
    add 'maximum' infront of this '...... {DBVW.DT} <= CurrentDate'  condition
    if(({@FrmBalDt}(NotEqualto)" " and {@ToBalDt}(NotEqualto)"  ") and ({@FrmBalDt} = {@ToBalDt})
    and MAXIMUM({DBVW.DT} )<= CurrentDate)
    then maximum({@BalDate})
    else {@BalDate}
    if it is not working, Check where the condition is failing..
    or else try this also
    (not HasValue({?Client Id}) OR {DBVW.CLID} = {?Client Id}) and
    (not HasValue({?Base Currency Code}) OR {DBVW.BCCYCOD} = {?Base Currency Code}) and
    (not HasValue({?Account Type}) OR {DBVW.ACDES} = {?Account Type}) and
    (not HasValue({?Legal Entity Name}) OR {DBVW.CUST} = {?Legal Entity Name}) and
    (not HasValue({?Account Currency}) OR {DBVW.CCY} = {?Account Currency}) and
    (not HasValue({?Account Number}) OR {DBVW.ACNO} in {?Account Number}) and
    (not HasValue({?Account Group}) OR {DBVW.ACGRP} = {?Account Group}) and
    (not HasValue({?Show Latest Statement on or before}) OR {DBVW.DT} <= {?Show Latest Statement on or before}) and
    (if {?Activity Only} = "True" then ({DBVW.CT_CR} <>0 or {DBVW.CT_DB}0)
    ELSE if {?Activity Only} = "False" then ({DBVW.CT_CR} >=0 or {DBVW.CT_DB}>=0)) and
    (if {?Business Days Only} = "True" then (not(datepart("w",{DBVW.DT}) in 7,1) and
    (not HasValue({?Balance Date Range}) OR {@BalDate} = {?Balance Date Range}))
    else if {?Business Days Only} = "False" then ((not HasValue({?Balance Date Range})
    Up to this copy paste of your formula
    OR {@BalDate} = (if maximum({?Balance Date Range})>maximum({DBVW.DT} ) then maximum(date({DBVW.DT} )) else {?Balance Date Range}))))
    i think this may work, without your second formula
    regards,
    Salah
    Edited by: salahudheen muhammed on Sep 11, 2009 4:56 PM
    Edited by: salahudheen muhammed on Sep 11, 2009 5:02 PM

  • Date range validity evaluation in BRM table

    Lectori salutem, Gurus salutem,
    I'm using 7.3 sp03. I would like to achieve the following with BRM (bit simplified):
    a parameter, ABC, is passed to a ruleSetService, and needs to be evaluated.
    The table is as follows:
    ABC startDate endDate Value
    1 01-01-2011 31-12-2011 A
    1 01-01-2012 31-12-2012 B
    2 01-01-2011 31-12-2011 X
    4 01-01-2012 31-12-2012 Y
    When ABC-value '1' is passed to the ruleSetService in the table the first row needs to be selected. CurrentDate (24-11-2011) is in between 01-01-2011 and 31-12-2011, making this the valid row. The value that should be returned is A.
    Beginning of next year it should change to B.
    How should I set this up in BRM?
    Thanks in advance!
    Martijn.

    Hi Martijn,
    Appreciate that you've simplifiied the scenario... but do you have any idea how many of these entries you are likely to have in total as that may change the answer.
    You have a couple of choices that might work here...
    1. You could a decision table... to hold your values (i.e. ABC and date range as conditions, value as action) and use the rule that evaluates the decision table to pick up the current date for the comparison. e.g.  date conditions would be "greater than than 01-01-2011", "less than 31-12-2011", etc.
    2. Alternatively, if the plan is to have a simple end of year change over,  you could use Effectivities (in the Project Resources of the rules project) to determine which values  are selected and use a decision table or even just a rule script to determine the value.
    But the thing is... HOW you organise your rule is going to depend a lot on:
    a) How many entries in total do you expect
    b) Is there a nice neat cutover of all ABC values at the same time or do effective date ranges vary a lot between different ABC values
    c) Who's responsible for maintaining these and if multiiple people are responsible do you need to organise your rule to cater for that? E.g. Are different people responsible for different ABC entries
    Does that help at all?
    Regards,
    Jocelyn

  • Pass a date Range from VB to a parameter

    Hello,
    I'm thinking this is an easy question, but ...
    In a Visual Studio 2008 VB program, I'm allowing the user to pick a starting and ending date from DateTimePickers. (works fiine).
    In a CR 2008 report, I have a paramter defined as "pDateRange",  Type = date, Allow Range Values = Yes.
    In the Record Selection, I use a formula of {tblData.INSTALLDT} in {?Date_Range}.
    When I run the report, I can enter the date ranges in via the Enter Values prompt screen, and it works file,
    All I need to know is - how do I pass the dates the user selected in the VB program to the pDateRange parameter?
    Thanks very much,
    Carl

    Thanks Ludek for the reply.
    Unfortunately, I canu2019t seem to puzzle this out.  None of the examples seem to work.  This is an example, along with their comments.
    I get the error "The parameter field current values cannot contain range values because the ValueRangeKind property is set to discrete." on the last line.
    I could REALLY use some help getting past this issue.
           Dim myReportDocument As New CRS_Tab_Prod_Org_Cnt_Params2
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As ParameterValues
            Dim crParameterRangeValue As ParameterRangeValue
            crParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
            'Access the individual subreport parameter field "Date_Range"
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("Date_Range")
            'Cast the variable to hold the values to pass to the Report before execution
            crParameterValues = crParameterFieldDefinition.CurrentValues
            'Cast the variable to hold the range value for the parameter
            crParameterRangeValue = New ParameterRangeValue()
            'Set the Date range and include the upper and lower bounds. Use the Cdate function as insurance
            'to ensure that the value passed is cast to the appropriate data type
            With crParameterRangeValue
                .EndValue = CDate("1/1/1997")
                .LowerBoundType = RangeBoundType.BoundInclusive
                .StartValue = CDate("12/20/1997")
                .UpperBoundType = RangeBoundType.BoundInclusive
            End With
            'Apply the Date range to the values to be passed to the Report
            crParameterValues.Add(crParameterRangeValue)
            'Pass the parameter values back to the report
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    Thanks for your help,
    Carl

  • Variable Exit - Last Three months date range based on Sy-datum

    Hi
    I have a requirement to filter last 3months data based on sy-datum. I have a variable filter on Posting Date.
    For e.g. Today is 20110622
    I have to determine below range: When users run the report prompt should be auto filled with below date range.
    From Value: 20110301
    To Value     : 20110531
    From sy-datum I can find the first day of the current month - In this scenario 20110601 (I'll replace last 2 characters with "01").
    If I subtract "-1" I'll get the To Value: 20110531
    Question is to get the "From Value". If I subtract 90days from To value, it will work for few months.
    For e.g. If my To value is Feb 28th and if I subtract 90days, I may get a different answer.
    Is there any better approach to determine this date range?
    Thanks for your help.
    Best Regards,
    Sree

    Hi Sree,
      Pleae find this approach and compare
    data : l_date type sy-datum,
    l_startdate type sy-datum,
    l_endate type sy-datum,
    l_startmonth(6) type c,
    l_endmonth(6) type c,
    l_date = sy-datum.   say "20110622
    l_endmonth = sydatum(6)   "201106
    Pass year month and get previous month using this standard .
              CALL METHOD cl_rs_time_service=>shift_year_month
                EXPORTING
                  i_year_month = l_endmonth
                  i_shift      =  -1
                RECEIVING
                  r_year_month = l_endmonth
                EXCEPTIONS
                  failed       = 1
                  OTHERS       = 2.
    "l_endmonth = 201105.
              CALL METHOD cl_rs_time_service=>shift_year_month
                EXPORTING
                  i_year_month = l_endmonth
                  i_shift      =  -2
                RECEIVING
                  r_year_month = l_startmonth
                EXCEPTIONS
                  failed       = 1
                  OTHERS       = 2.
    "l_startmonth = 201103
    l_startdate(6) = l_startmonth.
    l_startdate+6(2) = '01'.
    "l_startdate = 20110301
    We got startdate in and we want to get enddate , but we got endmonth ...
    now we need to get last date of the endmonth.
    Use this function module SLS_MISC_GET_LAST_DAY_OF_MONTH  and u can get it. Input should be date.
    so put l_enddate+6(2) = '01'.
    l_enddate(6) = l_endmonth.
    now pass end date to the  Function module and this will return the end date of the month.
    So you get l_startdate and l_enddate as you require. This will work for leap years or feb 28 days what ever...
    Regards
    vamsi
    Edited by: vamsi talluri on Jun 22, 2011 10:06 PM

  • Help with Date Range

    Hi,
    I have an Oracle form which allows users to enter :start_date_active(mandatory) and :end_date_active (can be null).
    I need to check in form using SQL if there already exists a record for this date range or if there is any overlapping date ranges for the value entered and disallow user from entering that.
    I have my query as follows:
    SELECT (1)
    FROM <table> xsv
    WHERE 1=1
    AND ( (:START_DATE_ACTIVE >= xsv.start_date_active) AND
    (:START_DATE_ACTIVE <= nvl(xsv.end_date_active,'31-DEC-4712'))
    OR
         (:END_DATE_ACTIVE >= xsv.start_date_active) AND
    (:END_DATE_ACTIVE <= nvl(xsv.end_date_active,'31-DEC-4712'))
    But, this incorrectly allows me to enter over lapping date ranges when the :end_date_active is null.
    It should work as follows :
    eg.
    start_date_active end_date_active
    01-Apr-2009 allowed
    01-Mar-2009 10-Mar-2009 allowed
    01-feb-2009 Not allowed, as it overlaps with 1st record
    10-feb-2009 05-Mar-2009 Not allowed, as it overlaps with 2nd record
    05-Mar-2009 20-mar-2009 Not allowed, as it overlaps with 2nd record
    and so on.
    How do I modify my query to deal with null end dates ?
    Many Thanks
    Shankar

    Hi, Shankar,
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data (You posted this. It would be better if it were formatted.)
    (4) Your best attempt so far (formatted) (You posted this, but since it's unformated, it's very hard to read.)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type these 6 characters
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
    Use different names for the parameters and the columns. For example, if the column is called start_date_active, call the corresponding parameter :p_start_date_active. It will help to keep them straight.
    In this statement, if the column end_date_active IS NULL, you're treating it as an impossibly late date:
    (:END_DATE_ACTIVE <= nvl(xsv.end_date_active,'31-DEC-4712'))That's good. (You should really use TO_DATE ('31-DEC-4712', 'DD-MON-YYYY'), though.)
    If it's possible for the parameter :end_date_active to be NULL, you should use NVL in the same way, to equate it with some appropriate date.
    The correct way to see if the range a to b (a <= b) overlaps with x to y (x <= y) is:
    WHERE   b >= x
    AND     a <= yIf you want an expression that's TRUE when they do not overlap, then say
    WHERE   NOT (    b >= x
                AND  a <= y
                )or, equivalently,
    WHERE   b < x
    OR      a > y

  • Select Row immediately previous and following a date range

    I have a query which returns two values within a given date range (colA, colB). This works great. However, I also need to return (in a separate query) the entries immediately previous and following this current date range (same two values).
    I am more familiar with MySQL where the query would include an "Order by date desc limit 1" for the row previous to the original query or "Order by date asc limit 1" for the row following the original query.
    What is the best way to return these rows within Oracle?

    Hi,
    This is an example of a Top-N Query, where you want to pick N items (N=1 in this case) from the top of an ordered list.
    This problem is a little trickier, because you want to pick from two lists, the rows before the specieifed date range (in descending order) and the rows after the range.
    The easiest way might be a UNION of two separate queries, using WHERE ROWNUM = 1 in each one.
    The solution below is easier to generalize, e.g. if you want the first and last row from each department.
    WITH
    e     AS
         SELECT     empno, ename, hiredate
         ,     ROW_NUMBER () OVER
              ( ORDER BY     CASE
                             WHEN hiredate < TO_DATE ( '01-JAN-1982'
                                            , 'DD-MON-YYYY'
                                            ) -- Start of date range
                             THEN hiredate
                        END
                        DESC     NULLS LAST
              ) AS pre_num
         ,     ROW_NUMBER () OVER
              ( ORDER BY     CASE
                             WHEN hiredate > TO_DATE     ( '31-DEC-1982'
                                            , 'DD-MON-YYYY'
                                            ) -- End of date range
                             THEN hiredate
                        END
              ) AS post_num
         FROM     scott.emp
    SELECT     empno, ename, hiredate
    FROM     e
    WHERE     pre_num          = 1
    OR     post_num     = 1
    ;Results (last hire before 1982 and first hire after 1982):
         EMPNO ENAME      HIREDATE
          7788 SCOTT      19-APR-87
          7900 JAMES      03-DEC-81

  • Grouping by month within date range

    Hi,
    I have a date range which I like to group by months, but not from the 1st to last date of the calendar month but by given start date.  For example the table below represents the date range with some values in a table.  So the
    first month range in the group should be from 06/06/2013 to 08/07/2013.  The 06/07/2013 is absent because it's Saturday.  In fact the data is populated with working days only.  
    Table below shows what I really would like to get:
    There is a simple calculation for each month anniversary date, if the value from the start date, 06/06/2013, here 12 is less than the next month anniversary date, 08/07/2013, which is 9, then it should ignore it.  And only show the value from the month
    who's anniversary date value is less than the first date value, 12.  So the example above shows value 14 for the second month's anniversary date, 06/08/2013.  If the value has been found in any month the show, and ignore the rest. 
    I am just interested if there are any and report which number of month and the value. 
    I can implement this in procedural way, such as in VBA, but because the above looped many times it will take hours to run the process.  I have tried in SQL Server, but first problem I came up with is that I can't group by month from the given start
    date.
     Is this possible to do in T-SQL ?

    I'm not sure I entirely understand your question.  So I'll break the answer into two parts.
    First, as I understand it, you are looking for a way to group data by months, but not all dates in June, 2013 as one group, all dates in July, 2013 as the next group, etc.  Instead you want all dates from June 6, 2013 to July 5, 2013 as the first month,
    all dates from July 6, 2013 to August 5 as the second month etc.  The way to do that is use
    DATEDIFF(month, '20130606', <your date column>) + CASE WHEN DAY(<your date column>) < 6 THEN -1 ELSE 0 END
    So you can assign the month number you want to every row when you select from your table by
    SELECT DATE, VALUE, DATEDIFF(month, '20130606', DATE) + CASE WHEN DAY(DATE) < 6 THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    Now as I understand it (but am not sure), you want the first value in each "month" (as you are defining "month" which is greater than the value contained in your start date and if no value in a particular month is greater than that value,
    you don't want any row for that month.  For that you could do something like
    Declare @StartDate date;
    Declare @StartValue int;
    Set @StartDate = '20130606';
    Select @StartValue = Value From <your table name>
    Where Date = @StartDate;
    ;With cteMonthNumber As
    (SELECT DATE, VALUE, DATEDIFF(month, @StartDate, DATE) + CASE WHEN DAY(DATE) < DAY(@StartDate) THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    WHERE DATE > @Date AND VALUE > @Value),
    cteOrdered As
    (Select DATE, VALUE, MonthNumber,
    ROW_NUMBER() OVER (PARTITION BY MonthNumber ORDER BY DATE) As rn
    From cteMonthNumber)
    Select MonthNumber, Value As KickOutValue
    From cteOrdered
    Where rn = 1;
    Tom
    P.S.  Notice that I wrote my date literal as YYYYMMDD.  This is a good idea in SQL Server since '20130806" will always be interpreted as August 6.  But depending on the settings on your server and/or client '06/08/2013' might be dd/mm/yyyy
    and so be August 6, but it might be interpreted as mm/dd/yyyy and be June 8.
    It is also a good idea to express date literals in this forum as yyyymmdd.  There are a lot of us on the forum from the United States and we think 06/08/2013 is June 6 and a lot of us from other places who think 06/08/2013 is Aug 8.  If you give
    your dates as yyyymmdd we don't have to try to figure out what format you are using.

  • IP : Delete a value in e cell without entering zero

    We have an input ready planning layout created with WAD. In WEB user deletes a value in a cell without entering zero instead. When we refresh data former value appears again. When the user enters zero to the cell we have no problem. When we execute the query with BEX and delete the value in cell without entering zero, there is no problem also. Is there a parameter in WAD to check this?

    Hi
    If you create a "Delete" function and provide the same on layout it will delete the same from the cube. However, the user need to enter the line # which he/she wants to delete from the layout. Ofcourse, entering zero in the input for Key Figure will help delete the values from cube but if it has any corresponding calculations (say salary or revenue)....it will not get nullified. It is always good idea to provide a standard delete function on the layout.
    Regards
    Srinivas

  • SUM(Case how to use this structure to get average values over date range

    I am using:
    Oracle SQL Developer (3.0.04) Build MAin-04.34 Oracle Database 11g Enterprise Edition 11.2.0.1.0 - 64bit Production
    How do I use the sum function with a case structure inside.
    so I have data that looks like has an ID, date, and value. I am looking to get the 7 day average for the date range of 4/1/2013 thru 4/20/2013
    with t as (
    select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, 10 Value_num from dual union all
    select 1 ID_key,to_date('4/2/2013','mm-dd-yyyy'), 15 from dual union all
    select 1 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 20 from dual union all
    select 1 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/8/2013','mm-dd-yyyy'), 12 from dual union all
    select 1 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 8 from dual union all
    select 1 ID_key,to_date('4/10/2013','mm-dd-yyyy'), 6 from dual union all
    select 1 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/14/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 5 from dual union all
    select 1 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 2 from dual union all
    select 1 ID_key,to_date('4/20/2013','mm-dd-yyyy'), 3 from dual union all
    select 2 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 12 from dual union all
    select 2 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 15 from dual union all
    select 2 ID_key,to_date('4/6/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/7/2013','mm-dd-yyyy'), 7 from dual union all
    select 2 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/11/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 6 from dual union all
    select 2 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 8 from dual union all
    select 2 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/18/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/19/2013','mm-dd-yyyy'), 5 from dual
    )**Please let me know if the table does not load.
    I would like to get the 7 day average as long as there is date for that row has enough previous dates, it not then it will return null.
    the results should look like this
    ID_Key      date_val     Value_num     7Day_Avg     7Day_Avg2
    1     4/1/2013     10          null          null
    1     4/2/2013     15          null          null
    1     4/3/2013     20          null          null
    1     4/5/2013     0          null          null
    1     4/8/2013     12          6.71          11.75
    1     4/9/2013     8          5.71          10.00
    1     4/10/2013     6          3.71          6.50
    1     4/12/2013     10          5.14          9.00
    1     4/13/2013     0          5.14          7.20
    1     4/14/2013     0          5.14          6.00
    1     4/15/2013     10          4.86          5.67
    1     4/16/2013     5          4.42          5.17
    1     4/17/2013     2          3.85          4.50
    1     4/20/2013     3          2.86          4.00
    2     4/3/2013     12          null          null
    2     4/5/2013     15          null          null
    2     4/6/2013     5          null          null
    2     4/7/2013     7          5.57          9.75
    2     4/9/2013     10          7.00          9.80
    2     4/11/2013     5          6.00          8.40
    2     4/12/2013     0          3.86          5.40
    2     4/13/2013     0          3.14          4.40
    2     4/15/2013     6          3.00          4.20
    2     4/16/2013     8          2.71          3.80
    2     4/17/2013     0          2.71          3.17
    2     4/18/2013     10          3.43          4.00
    2     4/19/2013     5          4.14          4.83As you may notice, there are gaps in the dates, so the value are then treated as zeros for the 7Day_Avg and then ignored for teh 7Day_Avg2 (not counted as number of days averaged do to no valu_num row)
    I was trying something like this to start, but getting error "missing keyword"
    select
    t.*/,
    sum(
          case
            when date_val between :day2 - 6 and :day2
            then value_num between date_val - 6 and date_val
            else null
            end
            as 7Day_avg
    form tShould I have the case structure outside the sum function?
    Any thoughts??
    Edited by: 1004407 on Jun 7, 2013 11:06 AM

    Hi,
    If you want the average of the last 7 days, including the current day, then then RANGE should be 6 PRECEDING, not 7.
    Try this:
    WITH     got_min_date_val AS
            SELECT  id_key, date_val, value_num
            ,       MIN (date_val) OVER () AS min_date_val
            FROM    t
            WHERE  date_val BETWEEN TO_DATE ('04-01-2013', 'mm-dd-yyyy')
                             AND   TO_DATE ('04-20-2013', 'mm-dd-yyyy')
    SELECT    id_key, date_val, value_num
    ,         CASE
                  WHEN  date_val >= min_date_val + 6
                  THEN  SUM (value_num) OVER ( PARTITION BY  id_key
                                               ORDER BY      date_val
                                               RANGE         6 PRECEDING
                        / 7
              END  AS avg_7_day
    ,         CASE
                  WHEN  date_val >= min_date_val + 6
                  THEN  AVG (value_num) OVER ( PARTITION BY  id_key
                                               ORDER BY      date_val
                                               RANGE         6 PRECEDING
              END   AS avg_7_day_2
    FROM      got_min_date_val
    ORDER BY  id_key
    ,         date_val
    Output:
       ID_KEY DATE_VAL   VALUE_NUM  AVG_7_DAY  AVG_7_DAY_2
             1 01-APR-13         10
             1 02-APR-13         15
             1 03-APR-13         20
             1 05-APR-13          0
             1 08-APR-13         12       6.71        11.75
             1 09-APR-13          8       5.71        10.00
             1 10-APR-13          6       3.71         6.50
             1 12-APR-13         10       5.14         9.00
             1 13-APR-13          0       5.14         7.20
             1 14-APR-13          0       5.14         6.00
             1 15-APR-13         10       4.86         5.67
             1 16-APR-13          5       4.43         5.17
             1 17-APR-13          2       3.86         4.50
             1 20-APR-13          3       2.86         4.00
             2 03-APR-13         12
             2 05-APR-13         15
             2 06-APR-13          5
             2 07-APR-13          7       5.57         9.75
             2 09-APR-13         10       7.00         9.80
             2 11-APR-13          5       6.00         8.40
             2 12-APR-13          0       3.86         5.40
             2 13-APR-13          0       3.14         4.40
             2 15-APR-13          6       3.00         4.20
             2 16-APR-13          8       2.71         3.80
             2 17-APR-13          0       2.71         3.17
             2 18-APR-13         10       3.43         4.00
             2 19-APR-13          5       4.14         4.83
    Message was edited by: FrankKulash
    Sorry; I meant to reply to OP, not to Greg

  • Capitalise/close/delete asset under construction with zero value

    Hi,
    I have an AUC (aset under construction) with a zero value but I am unable to clear it as such.
    How can I remove the open AUC from the reports and close/delete it?
    Thanks
    Keeley

    Hi,
    Go to t-code AS02. On the "*deactivation on" field under "General" Tab enter the current date or the last posting date recorded for the asset. Save the changes.
    Regards,
    Melu

Maybe you are looking for

  • Problems with Dr Java and java jdk 1.6

    Well in my class we use the Dr Java IDE for our code. I tried downloading the jdk 1.6 and jre 1.6 to be up to date with the dr java. Everything went good but when i started Dr Java it said no compiler was found so i manually went and chose the tools.

  • Timeout Object Problem: Can't recreate scaling error

    In my movie there is a function that scales 3D objects over time using a timeout object. The 3D objects are in an array that is shuffled each round, and based on the outcome of the array shuffle, some 3D objects are scaled and some are not. I have be

  • Using isDigit on args

    Hi am trying to use is digit on specific args to handle non numeric operands wilthout using exception handlers I have tried various ways but am having no luck and have not found any answers in the tutortials most recent attempt as follows: // Calcula

  • Continuous Data Protection - Only for 32-bit platforms?

    I want to install in Windows 7 or Windows 2008 64bit. Thanks.

  • ITunes library grows when I re-import a song in lower definition

    Here is the problem: my library is becoming too big to fit in my mobile devices. I had many CD's that I had initially imported in lossless definition. To save space, I decided to re-import the same CD's in lower definition (320kpbs). When prompted by