Loop is adding one to the counter and it isn't getting to row 1

I think what you need is a migration plan written out.
Lay out all of your FK and Check Constraints, and dependencies and hierarchies

For example
Employees have dependency on state
Counties have dependency on state
=> Populate State First
=>Then Populate Employees
=> Then Populate Counties

With a loop and check error you will grow a full white beard by the time it finishes.

Instead of checking state does not exist (AZ) and skipping and logging, you create state so it does exist (AZ) before populating employees for that state (AZ) no muss no fuss.

insert into **databaseb**.dbo.states
select distinct state 
from **databasea**.dbo.employees e
where not exists(select 1 from states tgt where e.state = tgt.statename)

Then when you go to insert all employees

Here are my check constraints

dbo.Employee Age ([Age]<(21))
dbo.Employee Salary ([Salary]>(0))
insert into **databaseb**.dbo.employees
select id, name, s.stateid
from **databasea**.dbo.employees e
join states s on e.state = s.statename
where Salary > 0 and Age < 21

preemptive approach

have you thought of MIGRATION software !!!

or

SSIS Packages

data migration is an old old old concept
surely there are plenty of automation tools !!!

just a thought !!

Open Source .. Software ...
or
TRIAL Premium software

SSIS is a great solution for migration, but it wont solve the issue of FK and Check constraints out of the box

hi

how about merge statement !! may be this could help !!

The technique outlined here to make merging more helpful involves wrapping the merge statement in a stored procedure and passing in the data as a table valued parameter

I am looking at SSIS aswell.
This is a project for sure.

I like my loop and reading all the foreign keys ahead of time, but boy is that a lot of work.

Thanks i am appreciating all the advices.

SSIS wont necessarily solve your problem. Its not so much the tool you are using, it's the methodology you are using with the tool. If you like loop in TSQL then in SSIS you will still opt for loops which is doable I guess. But it is up to you and what you feel comfortable with