Date selection of appropriate row

We have a table that stores the date and currency rate applicable for that day. A new row is inserted each day. However, there may be times when we don't get a new row inserted for a day or two.
For example:
EFFECTIVE_DATE     USD    GBP
15/03/2010           1    0.56
16/03/2010          1    0.58
19/03/2010           1    0.55
20/03/2010           1    0.57I am trying to write a function that will say what the GBP rate was if a user supplies the date they're interested in. So if they run the code supplying '17/3/2010', I need to return 0.58, because that was the rate last set before that date, there being no actual row that explicitly applies to that date.
I obviously can't have code that says 'where effective_date = user_supplied_date', because there's no row that equals what the user supplies, necessarily. But I am stumped coming up with how I say the effective date must be greater or equal to the user_supplied_date and less than the next effective date in the table after the first one that meets that criteria.
Any clues, please?! Something tells me it's probably trivial, but I'm having a logic block over this one!

Thank you for both of these: I will certainly check them out.
I did have a logic moment in the shower this morning, however: surely, it's OK to simply select the maximum date which is less than or equal to the supplied date? If so, then this query would do the job, I think:
select max(effective_date) from
  (select effective_date from currency_rates where effective_date<='date_as_supplied_by_user');...and then, knowing which date should be considered really effective, it's trivial to select the correct GBP amount with a further round of nesting:
select gbp from currency_rates where effective_date= 
(select max(effective_date) from
  (select effective_date from currency_rates where effective_date<=to_date('18/03/2010','DD/MM/YYYY')));  If this is a serious logic fail on my part, I'd not be surprised, though. Your dense rank example is really nice, too.

Similar Messages

  • Select First 10 rows of data based on dates

    Hi,
    Have a report like this
    "Object Name", "Object Type", "Complexity", "Task Name", "RCCL Close Date"
    ABC XXX MEDIUM Design 1-1-2008
    BBC XXX MEDIUM Design 2-1-2008
    ABC XXX MEDIUM Design 3-1-2008
    BBC XXX MEDIUM Design 4-1-2008
    ABC XXX MEDIUM Design 5-1-2008
    BBC XXX MEDIUM Design 6-1-2008
    ABC XXX MEDIUM Design 7-1-2008
    BBC XXX MEDIUM Design 8-1-2008
    ABC XXX MEDIUM Design 9-1-2008
    BBC XXX MEDIUM Design 10-1-2008
    ABC XXX MEDIUM Design 11-1-2008
    BBC XXX MEDIUM Design 12-1-2008
    ABC XXX MEDIUM Design 13-1-2008
    BBC XXX MEDIUM Design 14-1-2008
    ABC XXX MEDIUM Design 15-1-2008
    BBC XXX MEDIUM Design 16-1-2008
    How to select the first 10 rows using a sql query please suggest me..
    Thanks
    Sudhir.

    I tryed your code but this is returning only the 10th row data not all 10 rows data please suggest me how to modify the code
    The code below is wht i am using to execute. when i put a condition rno >= 10 it is showing me the 10th row data.
    only single row. please suggest me in modifying the code
    select
    from
    select
    "Project Name",
    "Object Name",
    "Object Type",
    "Complexity",
    "Task Name",
    "Actual Effort",
    "Plan Effort",
    "Close Date",
    --count(*) over (partition by "Object Name" order by "Close Date" ) recs
    row_number() over(order by "Close Date") rno
    from
    SELECT
    "Project Name",
    "Object Name",
    "Object Type",
    "Complexity",
    MAX("Task Name") "Task Name",
    SUM("Actual Effort") "Actual Effort",
    SUM("Plan Effort") "Plan Effort",
    MAX("Close Date") "Close Date"
    FROM
    SELECT
    "Project Name",
    "Object Name",
    "Object Type",
    "Complexity",
    MAX("Task Name") "Task Name",
    SUM("Actual Effort") "Actual Effort",
    SUM("Plan Effort") "Plan Effort",
    SUM("EV") "EV",
    MAX("Close Date") "Close Date"
    FROM
    SELECT
    INITCAP(pro.project_name) "Project Name",
    INITCAP(pobj.name) "Object Name",
    INITCAP(POBJ.PROGRAM_TYPE) "Object Type",
    INITCAP(POBJ.COMPLEXITY) "Complexity",
    INITCAP(tas.name) "Task Name",
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) ) "Actual Effort",
    CASE
    WHEN upper(:P68_TASK) LIKE UPPER('Incomming-Doc Review') Then SR.INCOMMING_DOC
    WHEN upper(:P68_TASK) LIKE UPPER('Design') Then
    SR.DESIGN
    WHEN upper(:P68_TASK) LIKE UPPER('Design Review') Then
    SR.DESIGN_REVIEW
    WHEN upper(:P68_TASK) LIKE UPPER('Design Rework') Then
    SR.DESIGN_REWORK
    WHEN upper(:P68_TASK) LIKE UPPER('Build') Then
    SR.BUILD
    WHEN upper(:P68_TASK) LIKE UPPER('Build Review') Then
    SR.BUILD_REVIEW
    WHEN upper(:P68_TASK) LIKE UPPER('Build Rework') Then
    SR.BUILD_REWORK
    WHEN :P68_TASK in ('Test Plan Prep','Unit Test Plan') Then
    SR.TEST_CASE_PREP
    WHEN :P68_TASK in ('Test Plan Review','Unit Test Plan Review') Then
    SR.TEST_CASE_REVIEW
    WHEN :P68_TASK in ('Test Plan Rework','Unit Test Plan Rework') Then
    SR.TEST_CASE_REWORK
    WHEN :P68_TASK in ('Testing','Unit Testing') Then
    SR.UNIT_TESTING
    WHEN :P68_TASK in ('Test Result Review','Unit Test Result Review') Then
    SR.TEST_RESULT_REVIEW
    WHEN upper(:P68_TASK) LIKE UPPER('Installation Review') Then
    SR.INSTALLATION_SCRIPT
    WHEN upper(:P68_TASK) LIKE UPPER('Release-Review') Then
    SR.RELEASE_REVIEW
    WHEN upper(:P68_TASK) LIKE UPPER('FDD Review') Then
    SR.FDD_REVIEW
    End "Plan Effort",
    CASE
    WHEN upper(:P68_TASK) LIKE UPPER('Incomming-Doc Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.INCOMMING_DOC,0)
    ) / decode(SR.INCOMMING_DOC,0,null,SR.INCOMMING_DOC) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Design') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.DESIGN,0)
    ) / decode(SR.DESIGN,0,null,SR.DESIGN) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Design Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.DESIGN_REVIEW,0)
    ) / decode(SR.DESIGN_REVIEW,0,null,SR.DESIGN_REVIEW) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Design Rework') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.DESIGN_REWORK,0)
    ) / decode(SR.DESIGN_REWORK,0,null,SR.DESIGN_REWORK) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Build') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.BUILD,0)
    ) / decode(SR.BUILD,0,null,SR.BUILD) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Build Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.BUILD_REVIEW,0)
    ) / decode(SR.BUILD_REVIEW,0,null,SR.BUILD_REVIEW) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Build Rework') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.BUILD_REWORK,0)
    ) / decode(SR.BUILD_REWORK,0,null,SR.BUILD_REWORK) ) * 100 ),2)
    WHEN :P68_TASK in ('Test Plan Prep','Unit Test Plan') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.TEST_CASE_PREP,0)
    ) / decode(SR.TEST_CASE_PREP,0,null,SR.TEST_CASE_PREP) ) * 100 ),2)
    WHEN :P68_TASK in ('Test Plan Review','Unit Test Plan Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.TEST_CASE_REVIEW,0)
    ) / decode(SR.TEST_CASE_REVIEW,0,null,SR.TEST_CASE_REVIEW) ) * 100 ),2)
    WHEN :P68_TASK in ('Test Plan Rework','Unit Test Plan Rework') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.TEST_CASE_REVIEW,0)
    ) / decode(SR.TEST_CASE_REWORK,0,null,SR.TEST_CASE_REWORK) ) * 100 ),2)
    WHEN :P68_TASK in ('Testing','Unit Testing') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.UNIT_TESTING,0)
    ) / decode(SR.UNIT_TESTING,0,null,SR.UNIT_TESTING) ) * 100 ),2)
    WHEN :P68_TASK in ('Test Result Review','Unit Test Result Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.TEST_RESULT_REVIEW,0)
    ) / decode(SR.TEST_RESULT_REVIEW,0,null,SR.TEST_RESULT_REVIEW) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Installation Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.INSTALLATION_SCRIPT,0)
    ) / decode(SR.INSTALLATION_SCRIPT,0,null,SR.INSTALLATION_SCRIPT) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('Release-Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.RELEASE_REVIEW,0)
    ) / decode(SR.RELEASE_REVIEW,0,null,SR.RELEASE_REVIEW) ) * 100 ),2)
    WHEN upper(:P68_TASK) LIKE UPPER('FDD Review') Then
    trunc((((
    SUM( nvl(TCL.NUM_HOURS_DAY1,0) + nvl(TCL.NUM_HOURS_DAY2,0) +
    nvl(TCL.NUM_HOURS_DAY3,0) + nvl(TCL.NUM_HOURS_DAY4,0) +
    nvl(TCL.NUM_HOURS_DAY5,0) + nvl(TCL.NUM_HOURS_DAY6,0) +
    nvl(TCL.NUM_HOURS_DAY7,0) )
    nvl(SR.FDD_REVIEW,0)
    ) / decode(SR.FDD_REVIEW,0,null,SR.FDD_REVIEW) ) * 100 ),2)
    End "EV",
    NULL "Close Date"
    FROM
    timecard_lines tcl,
    project_objects pobj,
    tasks tas,
    projects pro,
    timecard_headers thr,
    TIMECARD_PERIODS TP,
    Sub_Proc_Replan SR
    WHERE
    pro.id = :P1_PROJECTS AND
    TP.ID = THR.TPD_ID AND
    tcl.pobj_id = pobj.id AND
    tcl.tas_id = tas.id AND
    pro.id = pobj.pro_id AND
    thr.id = tcl.thr_id AND
    pobj.id = tcl.pobj_id and
    PRO.ID = SR.PRO_ID AND
    POBJ.ID = SR.POBJ_ID AND
    upper(tas.name) like upper(:P68_TASK)
    and tas.name not in ('Wait Time','Wait time','Wait-Time','Project Management',
    'Quality Management','Offshore-Onsite','Wait_Time')
    and pobj.id in
    (SELECT distinct pobj.id
    FROM
    task_status ts,projects pro,project_objects pobj,task tsk
    ,employees emp,employee_project_pairs epp,REVIEW_ITEMS RI
    WHERE
    pro.id = :p1_projects and
    pobj.pro_id = pro.id
    and pro.id = ts.pro_id
    and pobj.id = ts.pro_obj_id
    and tsk.id = ts.task_id
    and emp.id = epp.emp_id
    and epp.pro_id = pro.id
    and ts.id = ri.ts_id
    and tsk.name in
    ('Incomming-Doc Review',
    'Incoming Doc- Review',
    'Incoming Doc- Review',
    'FDD - Review',
    'Architecture - Review',
    'Design Review',
    'Design - Review',
    'TDD - Review',
    'Build Review',
    'Build - Review',
    'Code - Review',
    'Code',
    'Test Result Review',
    'Test Result - Review',
    'UTR - Review',
    'Test - Review',
    'Installation Review',
    'Installation - Review',
    'Release-Review',
    'Release - Verification',
    'Migration & Release - Review',
    'Release - Review')
    and ts.status in ('CLOSE','ACCEPTED','closed')
    and ( upper(:P68_TASK) like '%'||upper(substr(tsk.name,1,5))||'%'
    or upper(:P68_TASK_NAMES) like '%'||upper(substr(tsk.name,1,5))||'%' )
    GROUP BY
    pro.project_name,pobj.name,tas.name,POBJ.PROGRAM_TYPE,POBJ.COMPLEXITY,SR."Effort",SR.INCOMMING_DOC,SR.DESIGN,SR.DESIGN_REVIEW,SR.DESIGN_REWORK,SR.BUILD,
    SR.BUILD_REVIEW,SR.BUILD_REWORK,SR.TEST_CASE_PREP,SR.TEST_CASE_REVIEW,
    SR.TEST_CASE_REWORK,SR.UNIT_TESTING,SR.TEST_RESULT_REVIEW,
    SR.INSTALLATION_SCRIPT,SR.RELEASE_REVIEW,SR.FDD_REVIEW
    UNION
    SELECT distinct
    INITCAP(pro.project_name) "Project Name",
    INITCAP(pobj.name) "Object Name",
    INITCAP(POBJ.PROGRAM_TYPE) "Object Type",
    INITCAP(POBJ.COMPLEXITY) "Complexity",
    NULL "Task Name",
    NULL "Actual Effort",
    NULL "Plan Effort",
    NULL "EV",
    decode(
    MAX(ts.close_timestamp),null,
    MAX(ts.REVIEWER_ACCEPTED_DATE),
    MAX(ts.close_timestamp) ) "Close Date"
    FROM
    task_status ts,projects pro,project_objects pobj,task tsk
    ,employees emp,employee_project_pairs epp,REVIEW_ITEMS RI
    WHERE
    pro.id = :p1_projects and
    pobj.pro_id = pro.id
    and pro.id = ts.pro_id
    and pobj.id = ts.pro_obj_id
    and tsk.id = ts.task_id
    and emp.id = epp.emp_id
    and epp.pro_id = pro.id
    and ts.id = ri.ts_id
    and tsk.name in
    ('Incomming-Doc Review',
    'Incoming Doc- Review',
    'Incoming Doc- Review',
    'FDD - Review',
    'Architecture - Review',
    'Design Review',
    'Design - Review',
    'TDD - Review',
    'Build Review',
    'Build - Review',
    'Code - Review',
    'Code',
    'Test Result Review',
    'Test Result - Review',
    'UTR - Review',
    'Test - Review',
    'Installation Review',
    'Installation - Review',
    'Release-Review',
    'Release - Verification',
    'Migration & Release - Review',
    'Release - Review')
    and ts.status in ('CLOSE','ACCEPTED','closed')
    and ( upper(:P68_TASK) like '%'||upper(substr(tsk.name,1,5))||'%'
    or upper(:P68_TASK_NAMES) like '%'||upper(substr(tsk.name,1,5))||'%' )
    group by pro.project_name,pobj.name,tsk.name,POBJ.PROGRAM_TYPE,pobj.complexity
    GROUP BY "Project Name","Object Name", "Object Type", "Complexity"
    WHERE "Task Name" IS NOT NULL
    GROUP BY "Project Name","Object Name", "Object Type", "Complexity"
    order by "Close Date"
    where rno >= 10
    and rownum <= 10
    Thanks
    Sudhir

  • Display of data in a single row

    Hi
    Here is my query:
    SELECT
    --Element Classification Details:
    pec.CLASSIFICATION_ID,
    pec.classification_name,
    pec1.classification_id "Sub Classification Id",
    DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions',
    'Others Voluntary Deductions', 'Other Deductions',
    'Personal Deductions', 'Personal Deductions',
    'Personal Voluntary Deductions', 'Personal Deductions',
    'Car Loan Deductions') "Sub Classification",
    pec1.parent_classification_id,
    scr.sub_classification_rule_id,
    --Element Details:
    pet.element_name, pet.element_type_id, pet.reporting_name,
    DECODE(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
    pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
    --Run Result Details:
    prr.run_result_id,
    TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)) "Amount",
    piv.NAME "Input Value",
    --Assignment Details:
    paa.assignment_id,
    --Time Period
    ptp.START_DATE, ptp.end_date,
    ptp.period_name "Payroll Period"
    FROM hr.pay_element_classifications pec,
    hr.pay_element_classifications pec1,
    hr.pay_sub_classification_rules_f scr,
    hr.pay_element_types_f pet,
    hr.pay_run_results prr,
    hr.pay_run_result_values prrv,
    hr.pay_input_values_f piv,
    hr.pay_assignment_actions assact,
    hr.per_all_assignments_f paa,
    hr.pay_payroll_actions payroll,
    hr.per_time_periods ptp
    WHERE
    pec.classification_id = pec1.parent_classification_id (+)
    AND scr.classification_id = pec1.classification_id
    AND pet.classification_id = pec.classification_id
    AND scr.element_type_id = pet.element_type_id
    AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
    AND prr.run_result_id = prrv.run_result_id
    AND piv.input_value_id = prrv.input_value_id
    AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
    AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
    AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
    AND ptp.TIME_PERIOD_ID = payroll.time_period_id
    AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
    AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
    AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
    AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
    AND pec1.classification_name LIKE '%Deduction%'
    AND piv.name = 'Pay Value'
    AND paa.payroll_id != 0
    AND paa.pay_basis_id != 0
    AND paa.ASSIGNMENT_ID = '560'
    I needed to display the amounts as separate columns pertaining to different elements or rather different sub classification of the elements
    This is the final expected result for the report:
    Employee Personal Deductions PD Amount Other Deductions OD Amt
    XYZ Element1 00000.00 Element3 0000.00
    Element 2
    Car Loan Deductions CLD Amt Total Deductions (Total of all three)
    Element4 00000.00 00000000.00
    Here Personal Deductions, Other, Car Loan etc. are grouping of elements (sub classifications)
    I have used MAX function to display the results as separate columns like this:
    SELECT
    --Run Result Details:
    prr.run_result_id,
    MAX(DECODE(pec1.classification_name, 'Personal Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal Deductions",
    MAX(DECODE(pec1.classification_name, 'Personal Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal V Deductions",
    MAX(DECODE(pec1.classification_name, 'Other Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Other Deductions",
    MAX(DECODE(pec1.classification_name, 'Others Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Others V Deductions",
    MAX(DECODE(pec1.classification_name, 'Car Loan Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Car Loan Deductions"
    /*--Assignment Details:
    paa.assignment_id,
    --Time Period
    ptp.START_DATE, ptp.end_date,
    ptp.period_name "Payroll Period"*/
    FROM hr.pay_element_classifications pec,
    hr.pay_element_classifications pec1,
    hr.pay_sub_classification_rules_f scr,
    hr.pay_element_types_f pet,
    hr.pay_run_results prr,
    hr.pay_run_result_values prrv,
    hr.pay_input_values_f piv
    /*hr.pay_assignment_actions assact,
    hr.per_all_assignments_f paa,
    hr.pay_payroll_actions payroll,
    hr.per_time_periods ptp*/
    WHERE
    pec.classification_id = pec1.parent_classification_id (+)
    AND scr.classification_id = pec1.classification_id
    AND pet.classification_id = pec.classification_id
    AND scr.element_type_id = pet.element_type_id
    AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
    AND prr.run_result_id = prrv.run_result_id
    AND piv.input_value_id = prrv.input_value_id
    /*AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
    AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
    AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
    AND ptp.TIME_PERIOD_ID = payroll.time_period_id
    --and pet.element_NAME like 'IVTB%' 
    AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
    AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
    AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE*/
    AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
    AND pec1.classification_name LIKE '%Deduction%'
    AND piv.name = 'Pay Value'
    --and paa.PRIMARY_FLAG like 'Y%'
    /*AND paa.payroll_id != 0
    AND paa.pay_basis_id != 0*/
    GROUP BY
    prr.run_result_id
    However, the fact is that my each element_type_id has each run_result_id, which means 1 element has 1 run result id. Thus, I cannot display the data in a single row.
    Can someone guide me on this? How can I display the data for an employee as a single row?
    Thanks and regards,
    Aparna

    SELECT EMP_ID,
         Sum(Decode(DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions','Others Voluntary Deductions', 'Other Deductions'),'Other Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Other deduction',
         sum(Decode(DECODE(pec1.classification_name,'Personal Deductions', 'Personal Deductions', 'Personal Voluntary Deductions', 'Personal Deductions'),'Personal Deductions'),TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Personal deduction',
         sum(DECODE(pec1.classification_name,'Car Loan Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Car deduction'
    FROM hr.pay_element_classifications pec,
    hr.pay_element_classifications pec1,
    hr.pay_sub_classification_rules_f scr,
    hr.pay_element_types_f pet,
    hr.pay_run_results prr,
    hr.pay_run_result_values prrv,
    hr.pay_input_values_f piv,
    hr.pay_assignment_actions assact,
    hr.per_all_assignments_f paa,
    hr.pay_payroll_actions payroll,
    hr.per_time_periods ptp
    WHERE
    pec.classification_id = pec1.parent_classification_id (+)
    AND scr.classification_id = pec1.classification_id
    AND pet.classification_id = pec.classification_id
    AND scr.element_type_id = pet.element_type_id
    AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
    AND prr.run_result_id = prrv.run_result_id
    AND piv.input_value_id = prrv.input_value_id
    AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
    AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
    AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
    AND ptp.TIME_PERIOD_ID = payroll.time_period_id
    AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
    AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
    AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
    AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
    AND pec1.classification_name LIKE '%Deduction%'
    AND piv.name = 'Pay Value'
    AND paa.payroll_id != 0
    AND paa.pay_basis_id != 0     
    I hope this may help!
    Brijesh

  • Restriction on date when date is in the rows

    Hello and Nappy New Year.
    I have a problem to create the report based on the business requirements. The report should be based on the General Ledger DSO present two columns: total for the day and total for the previous day (both for the same, selected GL accounts). The rows should be Plant and Calendar Date.
    What I expect is:
    Date               Total for this day     Total for previous day
    2008-12-01          100               0
    2008-12-02          200               100
    2008-12-03          400               200
    2008-12-04          450               400
    etc.
    I created the columns as restricted key figures: first one is <= Calendar day, second is < Calendar Day. Both of them are cumulated, as I need the total on selected GL accounts, not the operations created on the particular day. Unfortunately, when the report is run for the time period fromu2026 tou2026 it presents the same values in both the columns. Whatu2019s more, the value presented for the first day in period donu2019t contain values gathered from the days before. It looks like the restrictions u201C<=u201D and u201C<u201D donu2019t work correctly.
    Any idea how to implement the requirement like this?
    Arelis

    Hello
    Thank you for your answer, but unfortunately it doesnu2019t work as I expected.
    In the meantime I was thinking about another approach: To be able to create the restricted key figure, where the selection on the date will be
    - from 1990.01.01
    - to variable, where variable is the value of the date for the particular row (including or excluding, depending on the Key Figure, as described in the example very above)
    The variance of the selection would be:
    - less than variable described above
    - less or equal variable described above
    The problem is that I have no idea how to put the value of the characteristic from the row to the variable. With u2018replacement pathu201D I can use only query or variable, with u201Cformula variableu201D I can use the characteristic to create the Key Figure, but I cannot use it after that.
    Any idea?
    Arelis

  • Selecting only one row at a time

    Hi experts,
    i have following doubt regarding selecting rows from a db:
    Is there any way of selecting only one row AT A TIME from a dabase just to collect the data in rows instead of in a unique document containing all the rows?
    I would like you to ellaborate on this as i need to send only one row to the IE, and then other row, and so on... without throwing any error!
    I have seen that there are SELECT SINGLE and SELECT UP TO 1 ROW, but these two methods are only useful when retrieving only one row, and that does not match my requirements. I need to process all the rows but one by one..
    I know that we can use the receiver jdbc adapter as if it was a sender by means of its specific datatype, but how to do it row by row??
    Hope i had explained well..
    Thanks in advance and best regards,
    David

    Hi kiran,
    Yes, my table has 5 not null fields but i am selecting and updating fixes values so i think that I will definetely go for the next solution:
    SELECT * FROM t1 WHERE status='0' and ROWNUM<2;
    UPDATE t1 SET status='1' WHERE status='0' and ROWNUM<2;
    My only concern is if the update will take the same row that the select.... BTW, I think it will
    ..What do you guys think?
    I ve been trying to operate with your proposed queries but i received some errors. Your queries are very interesting but i think that with the above ones i meet my requirements as the status field will be 0 for not processed rows and 1 for precessed ones (and the update will look for the row that meets the same 'where' clause than the select, and then, and only then, it will set status='1').
    The only thing i have to care about is what i questioned before.
    Thanks a lot and best regards,
    David

  • Selection of a row in  a table

    Hi,
    I have a problem with JTable. ...i have just started working with JTables and still have not got a complete hang of how they function.
    I have a table whose model is "AbstractTableModel". I have different data in each row of the table therefore i have a celledtior and cell renderer per row. Each row is rendered as a combo box. There is only one column in that table. What i need to do is when the user clicks on any of these the rows in the table i need to evaluate what is the content in that row(in the combo box-It should be the values that have not been used up yet in the other rows...so basically as you add rows the combo box content will keep shrinking till all the possible vlaues are exhausted).
    I added a celleditor listener for every row. When the user clicks on the cell the event get's captured but the row value that shows up is not row the user selected. The value is always the previous selected row. Each cell is rendered as a combo box.
    For example if the user selected the first row in the table then the value of the row selected is -1. If the the user adds two more rows and selects the third row then the value selected is 0 (previos selected).
    What i cannot figure out is how in the world is this value obtained.
    Please help !! I tried everything i can think of to get the correct value of the row selected.
    Thanks a lot for your time and patience.
    Archana

    Hello Suman,
    Please, look at 'No First Select from Table' section of this blog: [/people/jarrod.williams/blog/2006/12/14/visual-composer-tips-and-tricks|/people/jarrod.williams/blog/2006/12/14/visual-composer-tips-and-tricks]
    Good luck,
    Ola

  • How to set the Default values for Info Objects in Data Selection of InfoPac

    Hi All,
    Flat file Extracion:
    How to set the Default values for Info Objects in Data Selection Tab  for Info Package
    ex: Fiscal Year Variant  Info Object having values 'K4' 'Y2' etc  in Flat file
    Initially  default value(not constant)  for this info Object value should be 'K4'  in Info Package
    If I set data selection value for this info object K4 it will retreive records with this selection only? how to handle
    Rgds,
    CV

    Hi,
    suppose as your ex. if you are having fiscalyear variant in the dataselection tab then specify K4 in the from column, again the ficalyearvariant row and click on insert duplicate row at the bottom . you will get another row . In that enter Y2 in the from column. now you can extract K4, y2 values .
    haritha

  • Trouble in data selection logic

    Hi All,
    I am hitting 4 tables for selecting some data using inner join. There are three user
    input fields which if filled, has to take part in data selection. These three input fields are independent of each other.
    so while writing select query, how can i take care of all the possiblilities(none of them filled -- every one of them filled ) in the
    most efficient way..?
    Thanks
    -pranati

    Hi,
    IN the select-options you can add NO-EXTENSION NO INTERVALS..Which can be used a parameter..And you have to use IN in the select statement to filter the data..
    Check this example
    TABLES: marc.
    <b>SELECT-OPTIONS: so_matnr FOR marc-matnr NO-EXTENSION NO INTERVALS.
    SELECT-OPTIONS: so_werks FOR marc-werks NO-EXTENSION NO INTERVALS.</b>
    DATA: t_marc TYPE STANDARD TABLE OF marc.
    START-OF-SELECTION.
    Get the first 100 rows.
      SELECT mandt matnr werks UP TO 100 ROWS
             INTO TABLE t_marc
             FROM marc
    <b>         WHERE matnr IN so_matnr
             AND   werks IN so_werks</b>.
      IF sy-subrc = 0.
        WRITE: / 'RECORD COUNT - ', sy-dbcnt.
      ELSE.
        WRITE: / 'NO RECORD FOUND'.
      ENDIF.
    Thanks,
    Naren

  • Infopackage data selection & deltas

    Hi BW Experts,
    I have a few questions about infopackage and delta loads:
    1) How to perform mulitiple data selection.  e.g. company codes 1000, 1001 and 5000?  I can't filter by From To data selection since I do not want to include companies 2000, 3000, etc. 
    2) How to perfrom delta loads for just the company codes 1000, 1001, etc.?
    I would appreciate any suggestions or advice.
    l_sap

    Hi ,
    First of all, what is the delta identifier you have for loading the deltas for 1000, 1001, etc.
    For your requirement, create 2 InfoPackages,
    1. For FULL loads - Here as advised by others do duplicate rows and maintain the company codes for which you want to do FULL load.
    Note: Daily full loads and you can delete the overlapping requests if your target is InfoCube.
    2. For DELTA loads - here maintain 1000, 1001, etc and start Init and following deltas.
    Sankar Kumar

  • I'm typing dates across the top row. I want the date to be 12/13 and the program changes it to Dec. 13. It is making me mad. How do I get it to stop doing the change? I want a numerical number.

    How do I get the numbers program to type a numerical date across the top row? It wants to change it to Dec. 13 instead of 12/13.

    Amy,
    I hope that you can forgive Numbers for converting the date you enter as 12/13 into the default format of "December 13, 2011", one that is popular with many users.
    You can change to any of the supported date formats by using the Cells Inspector, Date and Time options.
    Select the top row of cells and use the inspector to set the format. You may do this before or after making the entries.
    Jerry

  • How to restrict the default selection of first row in ALV  in Webdynpro

    Hi Experts,
    In webdynpro i used ALV to display the bulk amount of datas under a view container. While running it ll cme by default selection on first row. how to restrict that.....

    Hi Vimal,
    Whenever we create nodes then by default the Initialization lead selection property of  node is always checked. That why in the alv by default the first row is selected.
    To restrict this default selection just unchecked the Initialization lead selection property of your node.
    Regard
    Manoj Kumar

  • Select Single * and Select upto one row

    Hi all,
    Can anybody tell me what is difference between Select single * and select upto one row?
    And which one is better?
    Thanks in advance.......

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    Select Single is the best one compared to UPto one rows.
    Select Single will get the first record from the table which satisfies the given condition.So it will interact once with the database.
    UTO 1 rows will get the list of the records for the given match and iwll show the first record from the list.So it will take time to get the record.
    SELECT SINGLE VBELN from VBAK
    where MATNR = '1M20'.
    ---Thjis will get the first matched record and will display the record
    SELECT VBELN from VBAK
    where MATNR = '1M20' upto 1 rows.
    ---Thjis will get the list of matched records and will display the first record
    The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
    Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
    Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
    Thus Select Single will take much processing time when compare with Select UPTO 1 rows.
    Also
    check these threads..
    Difference between Select Single and Selct upto 1 row
    Difference between Select Single and Select upto 1 row
    Difference between select single and select upto one row
    Difference between 'select single *' and 'select upto 1 rows'
    difference between select single and select up to 1 rows
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • Select single and select upto 1 rows

    Hi
    What is the difference between select single and select upto 1 rows
    Performance wise which one is the best
    Regards,
    Maya

    Hi,
    Difference Between Select Single and Select UpTo One Rows
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly: to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    reward points if useful
    regards,
    ANJI

  • Data selection and Person selection

    Hi all,
    What is the difference between 'Data selection' and 'Person selection' in PNP screen.(PNP logical database)
    I searched so many . But couldn't find appropriate one. Still confusing.
    Can any one explain me with example?
    must use both at a time or any one selection is enough?
    Which situation use 'Data selection' and which situation use  'Person selection' ?
    Thanks in advance.

    thanks for all reply.
    I have one pernr 700098
    Hiring date : 01.01.2008 - 16.08.2008
    firing date : 17.08.2008 - 31.12.9999
    I developed a customized report using PNP LDB.
    If , I entered 01.01.2008 - 31.12.2008 in 'Data selection'
                  3 in employee status( active)
    or
    I entered 01.01.2008 - 31.12.2008 in 'Person selection'
                  3 in employee status( active)
    If , I entered 01.01.2008 - 31.12.2008 in 'Data selection'
                  0 in employee status( active)
    or
    I entered 01.01.2008 - 31.12.2008 in 'Person selection'
                  0 in employee status( active).
    In above all cases picking the same record. what is the use of PNP screen?
    after 'GET PERNR' pernr structure get the value of latest record from infotype P0000.ie firing record. Because it doesn't bother the status.
    For below case picking the proper one.
    If , I entered 01.01.2008 - 16.08.2008 in 'Data selection'
                  3 in employee status( active)
    or
    I entered 01.01.2008 - 16.08.2008 in 'Person selection'
                  3 in employee status( active)
    If , I entered 17.08.2008 - 31.12.2008in 'Data selection'
                  0 in employee status( active)
    or
    I entered 17.08.2008 - 31.12.2008 in 'Person selection'
                  0 in employee status( active).
    Plz any one clear me.
    Thanks.

  • SAP GRC 10.1 AMF No data selected when adding duplicate fields from separate tables for configurable data sources

    Hi There,
    In SAP GRC 10.0, our team had an issue where we could not add duplicate fields from separate table (see ERROR: Select Currency/UoM field for the selected analyzed fields). This was resolved by the SAP Note 1904313/ 1904314 (http://service.sap.com/sap/support/notes/1904313).
    We upgraded our system to SAP GRC 10.1 SP05 and could now add the duplicate fields from separate tables. SAP Note 1904313/ 1904314 was part of SAP GRC 10.1 SP03 so it makes sense that we, in a higher version (SP05), would be able to do this.
    The issue now is when we add the duplicate fields from different tables and run the Ad-hoc Query to test if the data source works correctly, the No Data Selected warning persists. This means that the data source provides no data for analysis, which is required to write our business rules.
    Below is an example:
    Basic data source with just one currency reference field EBAN-WAERS.
    When you run the Ad-Hoc Query you receive data.
    Basic data source with second currency reference field EKKO-WAERS.
    When you run the Ad-Hoc Query no data is found.
    Please also make reference to the following thread logged by my colleague (ERROR: Select Currency/UoM field for the selected analyzed fields)
    Any assistance to receive data with duplicate fields from separate tables will be highly appreciated.
    Thanking you in advance.
    Regards
    Gary Khan

    Hi
    following are the  error messages from dump
    hrtText
       There is already a line with the same key.
    hat happened?
       Error in ABAP application program.
       The current ABAP program "SAPLCKMS" had to be terminated because one of the
       statements could not be executed.
       This is probably due to an error in the ABAP program.
    rror analysis
       You wanted to add an entry to table "\FUNCTION-POOL=CKMS\DATA=T_DYN_CKMLCR",
        which you declared
       with a UNIQUE KEY. However, there was already an entry with the
       same key.
       This may have been in an INSERT or MOVE statement, or within a
       SELECT ... INTO statement.
       In particular, you cannot insert more than one initial line into a
       table with a unique key using the INSERT INITIAL LINE... statement.
    rigger Location of Runtime Error
       Program                                 SAPLCKMS
       Include                                 LCKMSF01
       Row                                     226
       Module type                             (FORM)
       Module Name                             DYNAMIC_PERIOD_CLOSING
    Source code where dump ocured
    222
    223           APPEND ht_ckmlpp TO t_add_ckmlpp.
    224           APPEND LINES OF ht_ckmlcr TO t_add_ckmlcr.
    225           INSERT ht_ckmlpp INTO TABLE t_dyn_ckmlpp.
    >>>>           INSERT LINES OF ht_ckmlcr INTO TABLE t_dyn_ckmlcr.
    227         ENDWHILE.
    Also I guess there is problem with material ledger in R/3 side
    I have never worked on material ledger before so dont hav idea of Tcode and tables in SAP R/3 for material ledger.
    Thanks
    Navneet

Maybe you are looking for