• Let me try to explain what's going on then..

    There is a Table Customers(Table A) which will get Customers Data as any new prospective Customers join the Product list. A single customer can Have multiple entries as its possible that two product Employees can refer the same customer and that too on the same date. After the data is in the table i need to create a stored procedure where it loops through customer rows and whenever two or more customers with the same name are present then it needs to compare their CreatedBy and CreationDate Columns

    if Case 1:

    CreatedBy are Different then the row which was created first based on CreationDate is Considered Valid .

    if Case 2:

    CreatedBy are same,then CreationDate are compared and

    if Case 2a:

    the Datediff between the two CreationDate is greater than Customer_lock(Table B) Value Both are considered as Valid ,in other sense the first customer row will not be updated.

    if Case 2b:

    the Datediff between the two CreationDates is equal to or less than Customer_lock(Table B) then only the one with Min(CreationDate) is Valid and the other row is invalid.

    I hope you get the idea...