• Totally agree with Julien, nice when the code works out of the box. Production for me is 2003 Standard SQL 2005. I restore to 2003 Small business SQL 2005.

    My error was "Cannot assign a default value to a local variable." I changed the variable declaration to:

    DECLARE @rowCount INT

    Set @rowCount = (SELECT COUNT(1) FROM #OrphanedUsers)

    DECLARE @i INT

    SET @i =1

    DECLARE @tempUsername VARCHAR(1000)

    Once that fix was in place the code worked like a charm. I've been looking for a quick fix for my SQL users that read and write to the db through ASP.NET stored procs. So in a nut shell, thanks for the code it got me on the right track.

    Cheers,

    Graham