Well, I am not sure if you got it, but let me explain.

In the for loop, the 'select count(*)......' statement gives me the total records where the c1rec.clnt_id = asd.clnt_id and c1rec.acct_id = asd.acct_id and c1rec.pty_id = asd.pty_id .

But, I want the script to have the 3 columns sorted. If the columns contain:
clnt_id acct_id pty_id
1 2 3
4 5 6
1 2 3

then it will go to the first record and get 1 2 3 and put it in the table 'acct_static_details'. The next time it will insert 4 5 6 in the same table. The third time, since the record already exists in the table, it will put the record in another table ' acct_static_details_exceptions'. But, if the records are sorted, then the script will take less time to execute. Is it possible to sort these records? I hope that I am clear.

Thanks.