×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Fill the blank from historical data

Fill the blank from historical data

Fill the blank from historical data

(OP)
Hi,

I have the data needs to be backed fill based on historical data because the data is not consistent (some day it's populated and some day it's not)
Below I have two tables (Transaction table and Account_Location table):

CODE

Transaction - capture daily transaction with account and location information.
TRAN_D         ACCT_N      LOCN_N      TRAN_A
2018-02-08     1234        A123        125
2018-02-07                 B123        125 
2018-02-06                 C123        100 
2018-02-05     3456        D123        500
2018-02-04                 B123        600
2018-02-03                 C123        100
2018-02-02     5678        E123        100
2018-02-01                 F123        200 

Account_Location_Hist - capture historical account and location, The account and location are unique for each date
LOCN_D         ACCT_N      LOCN_N      
2018-02-08     1234        A123
2018-02-07     9999        B123        
2018-02-07     1234        A123
2018-02-06     8888        B123
2018-02-05     7777        C123
2018-02-03     6666        B123
2018-02-03     1234        A123
2018-02-02     4444        C123        
2018-02-02     1234        A123
2018-02-01     1234        A123
2018-01-30     3333        F123        
2018-01-29     2222        F123 

We would like to backfill the transaction records that have blank account number with location information and join the account location history.
But we would like to pick up the most recent previous day account number (which is max(locn_d-1)) from historical data in account location history.
Then display how many days different from transaction date.

so the expected output after back fill would be

CODE

Transaction - capture daily transaction with account and location information.
TRAN_D         ACCT_N      LOCN_N      TRAN_A    DATE_DIFF
2018-02-08     1234        A123        125
2018-02-07     8888        B123        125           1  -- (picked up from 2018-02-06)
2018-02-06     7777        C123        100           1  -- (picked up from 2018-02-05)
2018-02-05     3456        D123        500
2018-02-04     6666        B123        600           1  -- (picked up from 2018-02-03)
2018-02-03     4444        C123        100           1  -- (picked up from 2018-02-02)
2018-02-02     5678        E123        100          
2018-02-01     3333        F123        200           2  -- (picked up from 2018-01-30) 

Thanks a lot for your help guys.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close