• DECLARE MC CURSOR READ_ONLY FOR

    SELECT [Str]FROM #Windows_Auth_Orphan_User

    OPEN MC

    FETCH NEXT FROM MC INTO @cmd

    WHILE (@@fetch_status <> -1)

    BEGIN

    IF (@@fetch_status <> -2)

    BEGIN TRY

    PRINT @cmd

    Execute (@cmd)

    END TRY

    BEGIN CATCH

    SELECT ERROR_NUMBER()ErrorNumber,ERROR_LINE() AS ErrorLine,ERROR_MESSAGE() AS ErrorMessage

    FETCH NEXT FROM MC INTO @cmd

    CONTINUE;

    END CATCH

    FETCH NEXT FROM MC INTO @cmd

    END

    CLOSE MC

    DEALLOCATE MC

    I made it and it worked for me. but not sure wether it is optimal or not ?

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)