Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
userid128223
Creator
Creator

Update, Append, Purge, Composite key

I have following data that has source QVD and daily qvd. Source needs to get modified on daily basis via updates from daily.qvd.

  • Uniq key is composed of:  EmpID+EmpName+CreateDate
  • Daily file will have duplicate data where only updateDate will indicate latest recods which needs to be kept.
  • Data that is similar in daily.qvd needs to be purged out based on latest Updatdate.

Daily.qvd

EmpIDEmpNameAmountTerminalNoCreateDateUpdateDate
123Joe$200201/6/20141/6/2014
123Joe$100,000201/6/20141/7/2014
123Joe$500,000201/6/20141/9/2014
123Joe$400401/8/20141/8/2014
235Doe$55201/8/20141/22/2014
235Doe$200,000201/8/20142/1/2014
235Doe$500501/15/20141/15/2014
345Kim$456561/9/20141/9/2014
724Mele$25201/18/20141/18/2014
887Duwane$15301/22/20141/22/2014

Source.QVD

EmpIDEmpNameAmountTerminalNoCreateDateUpdateDate
123Joe$200201/6/20141/6/2014
123Joe$400401/8/20141/8/2014
235Doe$55201/8/20141/22/2014
235Doe$200,000201/8/20142/1/2014
345Kim$456561/9/20141/9/2014

FINAL RESULTS:

EmpIDEmpNameAmountTerminalNoCreateDateUpdateDate
123Joe$500,000201/6/20141/9/2014
123Joe$400401/8/20141/8/2014
235Doe$200,000201/8/20142/1/2014
345Kim$456561/9/20141/9/2014
724Mele$25201/18/20141/18/2014
887Duwane$15301/22/20141/22/2014
Labels (1)
20 Replies
Nicole-Smith

If you're new to SQL, start by going through this tutorial (http://www.w3schools.com/sql/default.asp?PHPSESSID=300ae3404d5fa2612f238abeebb8869c).  It's pretty simple and doesn't dive in very deep, but it should give you a good start.

If any of the answers above are correct or helpful, please mark them so that others can find solutions to their problems too

userid128223
Creator
Creator
Author

I did thanks, your solutions are simple easy to understand and to the point.

Thanks.

userid128223
Creator
Creator
Author

So if you did not have update date and only wanted to update records based on uniq key then you will use

where not exist (key) 

however because we had update date in the mix this time, you had to do inner join and group by clause.

Nicole-Smith

We could have gone the exists/not exists route for this example as well, but it works better using the inner join because it will take the newest data whether it's in the Daily or Source file.  (It's also less code to do it with the inner join.)

userid128223
Creator
Creator
Author

out of curiosity i tried this. I get all the records. why please explain

INNER JOIN (FINAL)

LOAD EmpID, EmpName, Amount, TerminalNo, CreateDate, max(UpdateDate) as UpdateDate RESIDENT FINAL

GROUP BY EmpID, EmpName, Amount, TerminalNo, CreateDate;

Nicole-Smith

You shouldn't be including Amount and TerminalNo, they make every row unique.  You only want the unique rows for EmpID, EmpName, CreateDate, and max(UpdateDate).

userid128223
Creator
Creator
Author

make sense amazing.

userid128223
Creator
Creator
Author

dont give me solution but just give me theory if you were to approach this using where not exist. how would you solve it.

In these kind of situation is there a rule of thumb, do you have theory on that. if its this then do that kind of scenario.

Nicole-Smith

Load all from Source adding a key for unique lines (EmpID and CreateDate).  Then load all from Daily where same key does not exist in Source.  Then you still need the inner join to get latest update date.

Nicole-Smith

Looking at your data, it seems that everything in Source is also in Daily, so why not just load Daily in for the newest UpdateDate?  (Maybe your example isn't like your actual data, but if it is, it seems like the Source part isn't even needed since all data would exist in Daily anyway.)