Inclusion of data based on date

Hello:
I need to extract data for patients who have more than 2 visits to the doctor.
My query is at the end of the post.
The criteria is to include only patients which a trait_date >= 09/01/2006 and have been seen 2 or more times from that date.
For example, Patient A has a date of 12/01/2007 and Patient B has a date of 9/01/2007, 12/12/2007, and 03/01/2008. The query needs to exclude Patient A because they only had one visit whereas Patient B had three visits and it is Patient B that should show up in the data.
I can't seem to figure out how to write the statement that would let me accomplish this.
Can someone help me?
Thank you in advance. Here is the code.
select a.dwkey_patient, a.date_of_birth, TRUNC(months_between(sysdate, a.date_of_birth)/12) AGE,
      b.dwkey_traittype, b.trait_date, b.trait_value
from dd.patient_dim a, search.document_traits b
where a.dwkey_org = b.dwkey_org
and a.dwkey_patient=b.dwkey_patient
and a.dwkey_org=45
and b.dwkey_traittype IN (36883,36885,36884) and b.dwkey_traittype <> 36391
and b.trait_date >= '01-SEP-06'
and (b.trait_value <= '35' or b.trait_value = 'Y')
and TRUNC(months_between(sysdate, a.date_of_birth)/12) >= 18
order by age asc, a.dwkey_patient asc, b.trait_date asc;Edited by: nyc2292 on Nov 7, 2008 12:03 PM

WITH PATIENTS AS (SELECT 1 ID, 'Patient 1' NAME FROM DUAL
                  UNION ALL
                  SELECT 2 ID, 'Patient 2' NAME FROM DUAL
     VISITS   AS (SELECT 1 PATIENT_ID, TO_DATE('01.01.2008', 'DD.MM.YYYY') VISIT_DATE,'Illness' REASON  FROM DUAL
                  UNION ALL
                  SELECT 1 PATIENT_ID, TO_DATE('01.01.2007', 'DD.MM.YYYY') VISIT_DATE, 'Pregnant' REASON FROM DUAL
                  UNION ALL
                  SELECT 2 PATIENT_ID, TO_DATE('01.01.2007', 'DD.MM.YYYY') VISIT_DATE,'Hungry' REASON  FROM DUAL
                  UNION ALL
                  SELECT 2 PATIENT_ID, TO_DATE('01.01.2006', 'DD.MM.YYYY') VISIT_DATE, 'Thirsty' REASON FROM DUAL
SELECT ID,
       NAME,
       REASON
  FROM (
  SELECT ID,
         NAME,
         REASON,
         COUNT(*) OVER (PARTITION BY PATIENT_ID) VISITS
    FROM PATIENTS,
         VISITS
   WHERE ID=PATIENT_ID
     AND VISIT_DATE>TO_DATE('01.09.2006', 'DD.MM.YYYY')
WHERE VISITS>1

Similar Messages

  • Getting aggregated data based on Date in Webi.

    Hi,
                  I have a requirement to display last 6 Months Receviables Month Wise in Webi. And i am getting data based on clearing Date in Bex query. And data from Bex query will be like
           Month             Measure
         01.01.2014       12
         06.01.2014       15
         15.01.2014       16
        02.02.2014        8
        05.02.2014       10
        12.03.2014        4
        14.03.2014        6
        18.03.2014       10
        21.03.2014        20
        30.03.2014       30
       03.04.2014        30
    And i want aggregated data as
    Month  Measure
    Jan      43
    Feb     18
    Mar     66
    Apr     30

    Hi Satish,
    Have you tried below:
    Create Month1 object as =Month([Month]) and [total]as =Sum([Measure])
    Then drag both Month1 and total objects in report block.
    Regards,
    Yuvraj

  • Problem when sorting data based on date

    I am trying to sort the following data based on the Transaction Receipt date column,unable to do it usi g the following syntax:
    <?sort:TRANSACTION_RECEIPT_DATE;'ascending';data-type='date'?>
    I have problem in converting the date in report to canonical date ,is there any other way to achieve the output without converting the date format.
    <?xml version="1.0"?>
    <!-- Generated by Oracle Reports version 6.0.8.27.0 -->
    <RECDTREP>
    <LIST_G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO104</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>24636</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863063</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO107</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>24641</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863068</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO123</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>24658</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863086</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO75</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>31-MAR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>22190</OBJECT_ID>
    <INITIALIZATION_DATE>14-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510860842</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>31-Mar-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>971515</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO116</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>25-JUN-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>64271</OBJECT_ID>
    <INITIALIZATION_DATE>30-JUN-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863077</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>25-Jun-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO92</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>31-MAR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>22253</OBJECT_ID>
    <INITIALIZATION_DATE>14-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510860890</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>31-Mar-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>971515</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO99</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>31-MAR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>22263</OBJECT_ID>
    <INITIALIZATION_DATE>14-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510860899</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>31-Mar-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>971515</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO109</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>25-JUN-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>64204</OBJECT_ID>
    <INITIALIZATION_DATE>30-JUN-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863070</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>25-Jun-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO135</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>25-JUN-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/18 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>64296</OBJECT_ID>
    <INITIALIZATION_DATE>30-JUN-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510875546</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>25-Jun-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO101</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>24618</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863046</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO120</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>24653</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863081</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO122</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>24657</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863085</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO127</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>24662</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863090</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO100</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>07-APR-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1></SNO_ATTRIBUTE1>
    <OBJECT_ID>24585</OBJECT_ID>
    <INITIALIZATION_DATE>07-APR-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863033</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO110</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>25-JUN-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/11 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>64265</OBJECT_ID>
    <INITIALIZATION_DATE>30-JUN-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510863071</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>25-Jun-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    <G_ASW_REC_DATE>
    <SNO_CREATED_BY>1433</SNO_CREATED_BY>
    <SNO_REQUEST_ID>-1</SNO_REQUEST_ID>
    <VENDOR_LOT_NUM>PO130</VENDOR_LOT_NUM>
    <SNO_CREATION_DATE>25-JUN-09</SNO_CREATION_DATE>
    <SNO_ATTRIBUTE1>2008/06/13 00:00:00</SNO_ATTRIBUTE1>
    <OBJECT_ID>64275</OBJECT_ID>
    <INITIALIZATION_DATE>30-JUN-09</INITIALIZATION_DATE>
    <ORGANIZATION_CODE>10</ORGANIZATION_CODE>
    <ORGANISATION_NAME>NDC - PARTS</ORGANISATION_NAME>
    <SERIAL_NUMBER>6510875487</SERIAL_NUMBER>
    <ITEM_CODE>3000.006</ITEM_CODE>
    <DESCRIPTION>ALLISON 3000 SERIES ON HWY TRANSMISSION E016392</DESCRIPTION>
    <MANUFACTURER>ALLISON</MANUFACTURER>
    <APPLICATION>On Highway</APPLICATION>
    <ITEM_COST>8879.02</ITEM_COST>
    <MATERIAL_COST>631.09</MATERIAL_COST>
    <CURRENCY_CODE>AUD</CURRENCY_CODE>
    <PO_UNIT_PRICE></PO_UNIT_PRICE>
    <TRANSACTION_RECEIPT_DATE>25-Jun-09</TRANSACTION_RECEIPT_DATE>
    <PO_NUMBER>982121</PO_NUMBER>
    </G_ASW_REC_DATE>
    </LIST_G_ASW_REC_DATE>
    <CF_SORT_BY>Manufacture,Receipt Date,Organization,Item Code</CF_SORT_BY>
    <CF_SERIAL_WHERE></CF_SERIAL_WHERE>
    </RECDTREP>

    HI Mahesh,
    <TRANSACTION_RECEIPT_DATE>07-Apr-09</TRANSACTION_RECEIPT_DATE>
    this is not a date,
    so you should change the query to get you the format in xsd format : YYYY-MM-DDThh:mm:ss+HH:MM
    otherwise, you have to write a custom sort function to decode and order it it.
    if you dont do the custom order and use
    <?sort:TRANSACTION_RECEIPT_DATE;'ascending';data-type='date'?>
    the data will be treated as string and you will see the row is sorted on string.

  • Read data based on date in internal tables

    Hi Abapers,
    In my zreport , i am retreving data from vbrk, vbrp into one internal table ( itab1) and retreiving data from customized table i nto internal table itab2.
    itab1 contains following fields.
    matnr - Material code
    erdat - date ( billing date).
    itab2 contains following fields.
    matnr - material code.
    zfromdate - from date
    ztodate  - to date
    zstprs - material price
    loop at itab1 .
    endloop.
    how to read particular record from itab2 ( which consists of material code with price maintaing with  date range )  based on my billing document date i.e erdat 
    ex: material code     fromdate             todate           price
         10000          01.11.2008     20.11.2008     100.
         10000          21.11.2008     30.11.2008     104
    if for example in itab1 , erdat ( billing doc date is 15.11.2008 ) , how to read first record in itab2 which will fall under that date range.
    please give me any suggestions, or provide sample code.
    regards,
    Hari priya

    Hi,
    Please go in this way
    while selecting fileds from table into itab2
    select in this way
    select * from  <tablename> into tabel itab2 where
      matnr = itab1-matnr and
      zfromdate LE erdat and
      ztodate   GE erdat.
    Loop at itab2.
    read table itab1 with key matnr = itab2-matnr.
    take ur fields into internal table
    endloop.

  • How to group data based on date

    In my program the internal table is returning several values based on date.
    for example for the first pernr in the image below  there are four records. i need to delete the first record which is between the dates 20 and 30 .
    and also i need to get the difference between the dates as the record 23 and 28  i need to get separate dates as 24, 25..28.

    I am not sure if I understood your question correctly.
    From what I have understood, you can use the following logic.
    This logic will move all the records from lt_fields2 to another table lt_fields1 with begda between 20 and 30 of any month, except for the first record. It will also move records for every date between begda and endda of each record.
    You can alter the logic based on your exact requirement.
    declare another table lt_fields1 like lt_fields2.
    data del_flag.
    data prev_month(2) type c.
    sort lt_fields by pernr begda.
    clear del_flag.
    loop at lt_fields2 into wa_fields where begda+6(2) GE 20.
    * Delete the first record having date greater than 20 in a month for each pernr.
       at new pernr.
            clear del_flag.
       endat.
       if begda+4(2) NE prev_month.
           clear del_flag.
      endif.         
        if del_flag is initial. 
            del_flag = 'X'.
            continue.  " This record will not be moved to the final internal table.
       endif.
    * Add records for each date between begda and endda.
       append wa_fields to lt_fields1.
       prev_month = begda+4(2)
       while wa_fields-begda LT wa_fields-endda.
             wa_fields-begda = wa_fields-begda+1.
             append wa_fields to lt_fields1.
       endwhile.
    endloop.

  • Restrict Query Data based on Date range and Users

    Hi All,
    I have a few web reports that I need do restrict data based on Users.
    In all the queries i have an infoobject 0CALDAY, and  a User Entry range variable on it. Because of performance issues  I need to restrict the range of dates a User can see. Typically most of users could go to a max date range of 1 month back. But some others would need the ability to see data for much bigger range of dates.
    Pls suggest how should i go about with this. Should I have to enforce this at Variable level(user exit).... but then i might have to maintain a table for the users.. Is there any other way of doing it.
    thanks
    Raj

    Any thoughts ?

  • Getting the data based on dates

    Hi All,
    In my application i am not able to retrieve the data from database between two dates.
    while entering the dates i am entring using :
    + "',to_date('+ fromdate+ "','DD-Mon-YYYY HH24:MI:SS'),"
    as in database i have kept my fromdate type as "varchar2"
    So while selecting data i have written the query as :
    String sqlQuery =
                                  "select SID,SERVER_NAME,DOWNTIMETYPE,FROMDATE,TODATE,FROMTIME,TOTIME,TIMETAKEN,DOWN_REASON from SS_UPDOWNTIME where (FROMDATE >='"
    + frmdate
    + "'  OR  (FROMDATE between '"
    + frmdate
    + "' and '"
    + todate
    + "')) ";
    but i am not able to get the data between the two selected dates
    Regards,
    Anupama

    Hi Anupama,
    'between' wont work because you have taken dates as varchar2.
    Just try like this.
    Take "Date" type in database and in java take java.sql.Date
    java.sql.Date sqlDefaultDate = new java.sql.Date(System.currentTimeMillis());
    System.out.println("sqlDate: "+sqlDefaultDate);  
    //  this will be in the format 2008-11-13 , So we can pass sqlDefaultDate variable to backend
    Regards,
    Lakshmi Prasad.

  • Sql query to fetch data based on date conditons

    Hi All,
    We have to schedule a script that runs at 1:00 AM from Monday to Friday.
    The script will run a  sql query  ,that will fetch the data from sql database 2008 based on the below conditions.
    Case 1: If date = current Date then retrieve the data of the previous Date.
    Case 2: If date = Monday then retrieve the entries of Friday ,Saturday and Sunday.
    Please help us on how we can achieve this.
    Thanks

    Hi,
    Are you asking about Patrick's
    solution?
    If so I highly recommend NOT to use this solution. PLease read LMU92's
    and
    Visakh16's responses.
    Why not to use it?
    1. This solution is not deterministic!
    A deterministic algorithm is an algorithm which, given a particular input, will always produce the same output. This solution give different values for different setting! It is depending for example on "SET LANGUAGE" value
    As mentioned above if you try to use any other languge then English then this query will not work since you will never get the value "Sunday"
    2. Moreover! Even if you are using "SET LANGUAGE 'English'" then this
    solution depend on "SET DATEFIRST" and only take into consideration that the value can be 1 or 7, using any other value you will get that @weekendDateMod is null!
    What can you use?
    let's test some value first to get the solution yourself. We know that we don't care about "SET LANGUAGE" since I will not use any language dependency but we need to examine "SET DATEFIRST". Try to change the value from 1 to 7 and check
    the value of this query
    SET DATEFIRST 1 -- Change this value from 1 to 7!
    DECLARE @Sunday DATE = '2014-08-03' -- This is Sunday
    DECLARE @Munday DATE = '2014-08-04' -- This is Munday
    SELECT DATEPART(DW,@Sunday),DATEPART(DW,@Munday), @@DATEFIRST
    Can you see the behavior ?
    The results are hidden here (select the text and you will see them)
    DATEFIRST___Sunday_______Monday
    1___________7___________1
    2___________6___________7
    3___________5___________6
    4___________4___________5
    5___________3___________4
    6___________2___________3
    7___________1___________2
    assuming you did the exercise above yourself, then  you can now think now what is the filter that you need...
    You can use a filter on those two parameters together using "where DATEPART... and @@DATEFIRST...) or using one combine check. Can you think how?
    Notice that this value is always 2 on Monday! Regarding our setting
    (DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7
    Please Don't Go Down Before YOu Understand!
    Now we can go to the solution
    * I really hope that you read all and did the small exercise yourself! You can not become a developer by copy answers, and this is the reason that from the start I only gave you tha way and not the final query!
    DECLARE @CurrentDate DATE = '2007-08-20' -- This is only for testing since you should use the function GETDATE() instead
    DECLARE @MinDateToFilter DATE
    SET @MinDateToFilter = CASE
    WHEN ((DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7) = 2 THEN DATEADD(DAY,-4,@CurrentDate)
    ELSE DATEADD(DAY,-1,@CurrentDate)
    END
    SELECT *
    FROM sales.salesOrderHeader
    WHERE orderDate > @MinDateToFilter
    I hope this was useful :-)
    [Personal Site] [Blog] [Facebook]

  • How to get whole month date based on date

    hi
    i have data at cube with calday and calyear/month
    when ever i entre date like 17/03/2009 , i want output not from 17th , i need output whole month of march?
    please let me know

    Hi,
    Here is the solution:
    1. Create 'ZM_END' Customer exit variable on 0Calday.
      Properties: Mandatory
                  Intervel
                  Uncheck ready for Input
                  0calenderday   
    2. Create ZCDAY User entry Variable on 0Calday
      Properties: Mandatory
                      Single 
                      Check ready for Input
                      0calenderday   
    3. In columns create new selection and then drag & drop your Keyfigure and also Drag 0CALDAY and then restrict 0CALDAY with Variable - ZM_END
    If user will enter 17/03/2009, then the result is from 01/03/2009 to 31/03/2009. I think this is what you are expecting.
    DATA: ZT_SDT TYPE SY-DATUM,
                       SDT TYPE SY-DATUM,
                       ZT_DT1 TYPE SY-DATUM,
                       ZT_DY(2) TYPE N,
                       ZT_MT(2) TYPE N,
                       ZT_YR(4) TYPE N,
    WHEN 'ZM_END'.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCDAY'.
        IF sy-subrc = 0.
          CLEAR: l_s_range.
          ZT_SDT = loc_var_range-low.
          ZT_DY = '01'.
          ZT_MT = ZT_SDT+4(2).
          ZT_YR = ZT_SDT+0(4).
          CONCATENATE ZT_YR ZT_MT ZT_DY INTO ZT_DT1.
          CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
            EXPORTING
              DAY_IN                  = ZT_SDT
           IMPORTING
             LAST_DAY_OF_MONTH       = SDT
           EXCEPTIONS
             DAY_IN_NOT_VALID        = 1
             OTHERS                  = 2
          IF SY-SUBRC <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          l_s_range-low = ZT_DT1.
          l_s_range-high = SDT.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
      ENDLOOP.
    Thanks
    Reddy
    Edited by: Surendra Reddy on Mar 18, 2009 3:33 AM

  • How to fetch data based on dates ?

    How do i write the query for the below statements ?
    1) net_bank_cr from rm_memorandum for the previous year end 31st March
    2) net_bank_cr from rm_memorandum for the as on date
    3) net_bank_cr from rm_memorandum as one year prior to current reporting date
    The table structure of rm_memorandum is as given below:
    create table RM_MEMO
    AS_ON_DT DATE,
    PAID_CAPITAL NUMBER(20,2),
    TOTAL_OBE NUMBER(20,2),
    CR_EQI_OBE NUMBER(20,2),
    NET_BANK_CR NUMBER(20,2),
    ADJ_NET_BANK_CR NUMBER(20,2),
    DEP_CURREMT_CRR NUMBER(20,2),
    LIAB_OTH_CRR NUMBER(20,2),
    TOTAL_CRR NUMBER(20,2)
    )

    The following result includes all rows for the previous financial year relative to the current date.
    SQL> with t as
      2  (
      3    select to_date('31/12/2010', 'dd/mm/yyyy') As_On_Dt, 205 Net_bank_CR from dual union all
      4    select to_date('15/03/2011', 'dd/mm/yyyy'), 205  from dual union all
      5    select to_date('15/03/2011', 'dd/mm/yyyy'), 666  from dual union all
      6    select to_date('31/03/2011', 'dd/mm/yyyy'), 9856 from dual union all
      7    select to_date('31/03/2011', 'dd/mm/yyyy'), 521  from dual union all
      8    select to_date('05/04/2011', 'dd/mm/yyyy'), 20   from dual union all
      9    select to_date('07/05/2011', 'dd/mm/yyyy'), 965  from dual
    10  )
    11  --
    12  select *
    13  from t
    14  where  t.As_On_Dt between (case
    15                              when ( sysdate >  add_months(trunc(t.As_On_Dt, 'YYYY'), 3) - 1 ) then
    16                                add_months(trunc(add_months(sysdate, -12), 'YYYY'), 3) - 1
    17                              when ( sysdate <= add_months(trunc(t.As_On_Dt, 'YYYY'), 3) - 1 ) then
    18                                add_months(trunc(add_months(sysdate, -24), 'YYYY'), 3) - 1
    19                            end) + 1 -- plus 1 to ensure it is the 1st Apr
    20                     and
    21                            case
    22                             when ( sysdate >  add_months(trunc(t.As_On_Dt, 'YYYY'), 3) - 1 ) then
    23                               add_months(trunc(sysdate, 'YYYY'), 3) - 1
    24                             when ( sysdate <= add_months(trunc(t.As_On_Dt, 'YYYY'), 3) - 1 ) then
    25                               add_months(trunc(add_months(sysdate, -12), 'YYYY'), 3) - 1
    26                            end
    27  /
    AS_ON_DT  NET_BANK_CR
    31-DEC-10         205
    15-MAR-11         205
    15-MAR-11         666
    31-MAR-11        9856
    31-MAR-11         521Edited by: bluefrog on Sep 7, 2011 1:35 PM Ensure it is the 1st of Apr as the first date, hence add 1

  • Need help in fetching data based on date

    i want to  write the query for the below statements ?
    1) net_bank_cr from rm_memorandum for the previous year end 31st March
    2) net_bank_cr from rm_memorandum for the as on date
    3) net_bank_cr from rm_memorandum as one year prior to current reporting date
    The table structure of rm_memorandum is as given below:
    create table RM_MEMO
    AS_ON_DT DATE,
    PAID_CAPITAL NUMBER(20,2),
    TOTAL_OBE NUMBER(20,2),
    CR_EQI_OBE NUMBER(20,2),
    NET_BANK_CR NUMBER(20,2),
    ADJ_NET_BANK_CR NUMBER(20,2),
    DEP_CURREMT_CRR NUMBER(20,2),
    LIAB_OTH_CRR NUMBER(20,2),
    TOTAL_CRR NUMBER(20,2)
    )

    may be like ..
    WITH t AS
         (SELECT TO_DATE ('31/12/2010', 'dd/mm/yyyy') as_on_dt, 205 net_bank_cr
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('15/03/2011', 'dd/mm/yyyy'), 205
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('15/03/2011', 'dd/mm/yyyy'), 666
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('31/03/2011', 'dd/mm/yyyy'), 9856
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('31/03/2011', 'dd/mm/yyyy'), 521
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('05/04/2011', 'dd/mm/yyyy'), 20
            FROM DUAL
          UNION ALL
          SELECT TO_DATE ('07/05/2011', 'dd/mm/yyyy'), 965
            FROM DUAL)
    SELECT *
      FROM t
    WHERE t.as_on_dt
              BETWEEN   (CASE
                            WHEN (SYSDATE >
                                     ADD_MONTHS (TRUNC (t.as_on_dt, 'YYYY'), 3)
                                     - 1
                               THEN   ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12),
                                                         'YYYY'
                                                  3
                                    - 1
                            WHEN (SYSDATE <=
                                     ADD_MONTHS (TRUNC (t.as_on_dt, 'YYYY'), 3)
                                     - 1
                               THEN   ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -24),
                                                         'YYYY'
                                                  3
                                    - 1
                         END
                      + 1                    -- plus 1 to ensure it is the 1st Apr
                  AND CASE
              WHEN (SYSDATE > ADD_MONTHS (TRUNC (t.as_on_dt, 'YYYY'), 3) - 1)
                 THEN ADD_MONTHS (TRUNC (SYSDATE, 'YYYY'), 3) - 1
              WHEN (SYSDATE <= ADD_MONTHS (TRUNC (t.as_on_dt, 'YYYY'), 3) - 1)
                 THEN ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12), 'YYYY'), 3)
                      - 1
           ENDand result would be ....
    AS_ON_DT  NET_BANK_CR
    31-DEC-10         205
    15-MAR-11         205
    15-MAR-11         666
    31-MAR-11        9856
    31-MAR-11         521regards,
    friend

  • Deleting Data based on Date

    Hi, I am just looking for some help in regards to a table of data I have. Currently I have a list of 500k Job Ids and Time Values. I have managed to identify that I have alot of duplicate job ids and I was looking to find out how i can write a query to give me the first job id with the min date.
    An example of the data table is the following:
    Job ID      |      TimeStamp
    123ab      |     18-MAY-13 21:00:06
    123fg      |     18-MAY-13 21:05:32
    123ab      |     19-MAY-13 11:10:05
    If somebody could please advise, would really appreciate it.

    If you just want a TOP-N query to get the first row of each group, you can use a couple of different methods e.g.
    SQL> select deptno, hiredate from emp order by deptno, hiredate;
        DEPTNO HIREDATE
            10 09/06/1981
            10 17/11/1981
            10 23/01/1982
            20 17/12/1980
            20 02/04/1981
            20 03/12/1981
            20 19/04/1987
            20 23/05/1987
            30 20/02/1981
            30 22/02/1981
            30 01/05/1981
            30 08/09/1981
            30 28/09/1981
            30 03/12/1981
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, hiredate
      2  from (select deptno, hiredate, row_number() over (partition by deptno order by hiredate) as rn
      3        from emp
      4       )
      5* where rn = 1
    SQL> /
        DEPTNO HIREDATE
            10 09/06/1981
            20 17/12/1980
            30 20/02/1981
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, max(hiredate) keep (dense_rank first order by hiredate) as hiredate
      2  from emp
      3* group by deptno
    SQL> /
        DEPTNO HIREDATE
            10 09/06/1981
            20 17/12/1980
            30 20/02/1981
    Now if you want to actually delete duplicate records, that's a different matter.  A search of the forums for "delete duplicate" should give you plenty of examples.

  • Last 6 months of data based on date feild that is an integer data type

    Hi Folks
    I have a date column called 'YYYYMM' that is an Integer data type in YYYYMM format (eg. 201309). I want to return records from the last 6 months. 
    If the column was in a date format I could use something like 
    [YYYYMM] >DATEADD(M, -6, CURRENT_TIMESTAMP)
    Therefore I assume I need to do a CONVERSION of INT into a date format with something like
    CONVERT (DATE, [YYYYMM]
    But I get the message  "Explicit conversion from data type int to date is not allowed"
    Can someone suggested a work around?
    Many thanks Steve

    another way is this
    SELECT *
    FROM Table
    WHERE DATEADD(mm,(dateintfield%100)-1,DATEADD(yy,(dateintfield/100) -1900,0)) >=DATEADD(mm,DATEDIFF(mm,0,GETDATE())-6,0)AND DATEADD(mm,(dateintfield%100)-1,DATEADD(yy,(dateintfield/100) -1900,0)) < DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to select data based on date range

    Hi all,
    how do I make the following scenario happen:
    I am tracking my sales people's performance from 1/01/00 to 1/01/09, and I want to give $200 bonuses to only those whom made a sale between 1/01/06 to 1/01/08.  I need a formula that captures the sale between 1/01/06 to 1/01/08 and assign a $200 bonus that I can then insert into my report as a field. 
    I've been trying with the "If" "then" functions, and I'm unsure how to incorporate the date field into it. 
    please help!
    Thanks,
    Frank

    Hi Newbie,
    You will have to create the following formula, call it @Bonus and place it in the detail section:
    If {date.field} >= Date(2006,01,01) and
    {date.field} <= Date(2008,01,01) then
    200 else 0
    You can then summarize it however you want.
    I hope this helps,
    Regards,
    Zack H.

  • Getting past days data based on DATE data type column

    I am trying to extract last 2 days data using date data type column with below query,
    select * from tbl
    where col < col -2;
    this is not showing me any data. please help where i am making mistake. guide please. thx

    Hi,
    When you say "last 2 days" do you mean the 48 hours right before run-time?
    If so, you want to compare col to SYSDATE:
    select  *
    from    tbl
    where   col  >  SYSDATE - 2
    and     col  <= SYSDATE
    ;If you mean the "last 2 days" before some other event, then replace SYSDATE with that date in both places above.
    If you were trying
    where   col  >  col - 2then you should have been getting all rows that have a non-NULL col. If you were getting no results, then something is very wrong.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    If the results depend on when you run the query, then give a couple of different examples, with the run-time. for example "If I run this at 03:00:00 on July 1, 2012, then I should get ... but if I run ir at 15:00:00 on July 1, 2012, then the results should be ...".
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • Problem in getting sandbox path in Content Database

    Hello all, we have created a custom application using Oracle Content database API, which upload files to content database programmatically. For this we are using following code to retrieve sandbox try FdkCredential credential = new SimpleFdkCredentia

  • Windows 98 Sound Blaster H

    We recently had to re-fromat the hard dri've on an old computer running Windows 98. Our sound blaster software has been lost in our move and I am trying to download the latest drivers for Windows 98. Can someone point me in the right direction?

  • Bad execution plans when using parameters, subquery and partition by

    We have an issue with the following... We have this table: CREATE TABLE dbo.Test ( Dt date NOT NULL, Nm int NOT NULL, CONSTRAINT PK_Test PRIMARY KEY CLUSTERED (Dt) This table can have data but it will not matter for this topic. Consider this query (t

  • Exception in using rssutils.tld in jsp

    hi,I met an exception in using rssutils.tld My code is: <rss:feed url="http://rss.xinhuanet.com/rss/food.xml" feedId="food"/> <rss:forEachItem feedId="food" startIndex="0" endIndex="5"> <rss:itemTitle feedId="food"/> </rss:forEachItem> and it worded

  • Non site collection admins unable to create publishing sites

    I've come across a problem which a number of other people have found and blogged about a 'fix', this is where non site collection administrators are unable to create sub sites with the publishing site templates (both with and without workflow version