• rocky_498 - Saturday, April 22, 2017 2:03 PM

    Hi Chris,
    Sorry for the late reply. Just want to give you an update. It is working 95% fine but I am still missing 2 records to be linked. I want to take this opportunity and want to say Thank You for your time and help from last few days. If I come up with some kind of solution I will definitely let you know. I was thinking, is it make sense or even give a try If I use While or Cursor to pull that data what I need from two tables? or shouldn't waste my time to even try. Just want to know your experience advice.

    Thank You.

    While loops/cursors should be your very last resort for this type of problem - I'm absolutely sure that there is a set-based solution for you.
    You say that you have two rows which remain unlinked.
    1. Have you checked that there are matching rows available in the source table?
    2. Assuming that matching rows are available for these two rows in the target table, have you checked to see whether or not they are all used up on previous rows in the target table?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden