Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Help to write a select and update Queries

$
0
0
Hi,
I have a team member table and it has some wrong records which I have to find them in the below scenario and update them using correct query.

Table = TMMBR_DIM_H
It has TMMBR_I,Eff_D ,EXPR_D ,ACTV_F and DEL_F

here this table will have only one active record such as ACTV_F='Y' and DEL_F='N' , below one is the valid scenario and it is a valid recor
Code:


TMMBR_I        EFF_D              ACTV_F        EXPR_D              DEL_F
1603471        2009-08-19        N        2009-08-31        N
1603471        2009-09-01        N        2009-09-05        N
1603471        2009-09-06        N        2011-09-17        N
1603471        2011-09-18        N        2011-11-27        N
1603471        2011-11-28        Y        9999-12-31        N
1603471        2012-05-10        N        2012-05-18        Y

But the below example is not a valid a scenario and here I have to find all the records ,here you can see that expiry date supposed to be 2011-04-29 ,but it is showing another date , I have to find all these records from the table first and write a query to adjust them to the right date.

The logic is that all team member records should follow a sequencing of Eff data and Expr date which has Actv_F='N' and DEL_F='N' with active record.

Code:

TMMBR_I          EFF_D    ACTV_F        EXPR_D            DEL_F
437238        2009-05-24        N        2009-08-31        N
437238        2009-09-01        N        2010-04-03        N
437238        2010-04-04        N        2011-04-02        N
437238        2011-04-03        N        2011-05-15        N
437238        2011-04-30        Y        9999-12-31        N
437238        2011-05-16        N        2011-05-18        Y

I'm pasting two valid examples for more understanding.

Code:

TMMBR_I        EFF_D              EXPR_D              ACTV_F          DEL_F
2279189        2012-01-01        2012-02-15        N        Y
2279189        2011-10-23        2011-12-31        N        Y
2279189        2011-08-28        2011-10-22        N        Y
2279189        2011-08-03        9999-12-31        Y        N


Code:

TMMBR_I        EFF_D                EXPR_D            ACTV_F          DEL_F
2033224        2010-06-01        2010-07-28        N        N
2033224        2010-07-29        2010-08-03        N        Y
2033224        2010-07-28        9999-12-31        Y        N


Please help me in this regards.

Thanks in Advance. Anjan.

Viewing all articles
Browse latest Browse all 13329

Trending Articles