October 15, 2014 at 4:00 am
I currently need to relink 908 orphaned users ( Dont ask)
I ran EXEC sp_change_users_login 'Report' to get a list of them all, imported this into a table called dbo.orphaned
I now need to run exec sp_change_users_login 'update_one', 'username', 'username' against them all
I have created a cursor, but i dont know how to do the quotes around then username?? ANY advise would be appreciated!
DECLARE @name VARCHAR(50) -- username
DECLARE db_cursor CURSOR FOR
SELECT username
FROM DBA.dbo.Orphaned
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_change_users_login 'update_one', @name , @name
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
October 15, 2014 at 5:07 am
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply