Cursor quotation

  • 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

  • Use two quotes to represent a single quote inside a string, i.e.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply