Hi friends,
i have a cursor in which I am passing two parameters (eff_dt and empl_id).
In a table there can be more than one record for a employee with the diff effective date.
I want to do a select on a table when eff_dt is not null and table column effective date = parameter eff_dt then select the matching record but when eff_dt is not null and table column effective date doesn’t match with parameter eff_dt then select the latest effective dated record from the table.
So I wrote:
Select * from employee emp
Where emp.emplid = empl_id
And ( (eff_dt is not null and emp.effdt = eff_dt)
Or
Eff_dt is not null and emp.effdt (select max(effdt) from employee emp1
Where emp1.emplid = empl_id
And emp1.effdt != eff_dt)
)
if suppose there are 2 record with effective date 10th sep 2005 and 6th dec 2006 and I am passing eff_dt as 10th sep 2005 then according to me it should return o/p as 10th sep 2005 but with this select it is returning 6th dec 2006 which I wrong.
Can someone help me in solving my issue?
Thanks in advance.
i have a cursor in which I am passing two parameters (eff_dt and empl_id).
In a table there can be more than one record for a employee with the diff effective date.
I want to do a select on a table when eff_dt is not null and table column effective date = parameter eff_dt then select the matching record but when eff_dt is not null and table column effective date doesn’t match with parameter eff_dt then select the latest effective dated record from the table.
So I wrote:
Select * from employee emp
Where emp.emplid = empl_id
And ( (eff_dt is not null and emp.effdt = eff_dt)
Or
Eff_dt is not null and emp.effdt (select max(effdt) from employee emp1
Where emp1.emplid = empl_id
And emp1.effdt != eff_dt)
)
if suppose there are 2 record with effective date 10th sep 2005 and 6th dec 2006 and I am passing eff_dt as 10th sep 2005 then according to me it should return o/p as 10th sep 2005 but with this select it is returning 6th dec 2006 which I wrong.
Can someone help me in solving my issue?
Thanks in advance.