this question is an extension to http://www.experts-exchange.com/questions/28834639/restore-production-DB-with-replication-setup-to-a-test-platform.html#a41268750
they are highly related.
now we have restored the production DB to TEST platform and now we have a lot of orphaned users to fix using sp_change_users_login, once we ran this:
we have a list of this kind of users to fix and now I have to fix it one by one, any way to automate the whole thing and let the result of the command about plug into another script to execute them one by one using?
sp_change_users_login 'update_one', '<username>', '<username>'
we should ignore any SQL user id in production but not in TEST platform as it will show error, which doesn't matter:
Msg 15291, Level 16, State 1, Procedure sp_change_users_login, Line 208
Terminating this procedure. The Login name '<user name>' is absent or invalid.