• I think that you missed my point. A cursor IS a while loop (well, not exactly but it needs it to be useful).

    There's a different way to do that, but a for these kind of queries the cursors are fine because you're going one server (or one database) at a time.

    DECLARE @SQL varchar(8000);

    SELECT @SQL = STUFF((

    SELECT '

    UNION ALL

    SELECT loginame,

    hostname,

    dbname,

    cmd

    FROM OPENROWSET(''SQLNCLI'',''Server='+server_name+';Trusted_Connection=yes;'',''exec sp_who'')'

    FROM dbo.Tbl_ServerList

    FOR XML PATH(''),type).value('.', 'varchar(8000)'), 1, 11, '') ;

    INSERT INTO Capture_Logins

    EXEC(@SQL);

    You can find other alternatives for management such as the one explained here:

    http://msdn.microsoft.com/en-us/library/bb964743.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2