I have a dataset and I am trying to find results that reference each other. I have a table that has “Applications” in it. There are 2 parties (people) involved with an Application. These are the “Applicant” and the “Receiver”.
I need to find out how to obtain data where person “A” has been an Applicant and person “B” has been a Receiver and then where they have forwarded another Application in reverse. So where Person “B” is the Applicant and person “A” is the Receiver. I need to return both of those lines as 1 row in my result set.
My Data Structure looks like this:
Application ID, Applicant Name, Applicant DOB, Receiver Name, Receiver DOB
1, Bob SMITH, 12/06/1980, Joe SMITH, 10/10/1979
2, Joe SMITH, 10/10/1979, Bob SMITH, 12/06/1980
3, Betty DAVIS, 15/05/1986, Barry DAVIS, 29/07/1981
4, Barry DAVIS, 29/07/1981, Betty DAVIS, 15/05/1986
As you can see there are 4 applications but in reality only 2 “Cross Applications”. I am trying to get an end result to look like this showing the unique Cross Applications:
Application ID 1, Applicant Name 1, Applicant DOB 1, Receiver Name 1, Receiver DOB 1, Application ID 2, Applicant Name 2, Applicant DOB 2, Receiver Name 2, Receiver DOB 2
1, Bob SMITH, 12/06/1980, Joe SMITH, 10/10/1979, 2, Joe SMITH, 10/10/1979, Bob SMITH, 12/06/1980
3, Betty DAVIS, 15/05/1986, Barry DAVIS, 29/07/1981, 4, Barry DAVIS, 29/07/1981, Betty DAVIS, 15/05/1986
The only thing I can compare between the two Applications is the Name and DOB (This is a constraint placed on me. It’s annoying as sometimes people spell names differently or put in wrong DOB). I only want to return the cross applications, where both people are matched.
I think I’d need to load Row “N” into a cursor and compare the Name and DOB with every other row in the dataset (N+1 to N+n) and if any matches are found then to put them into the output and move on to the next row. I’m not sure how to do this and would like some help if anyone can give any advice. Thanks!
Kindly try the below