-- Have to EXEC the SQL, otherwise the SQL is evaluated -- for the linked server before it existsEXEC (@SQL)PRINT char(9)+'Populated [email protected]_Name+''' table with '+CONVERT(varchar,@@ROWCOUNT)+' Rows'

-- %%% Optional you may leave the Linked Server for other XLS operations-- Remember that the Linked Server will not create the XLS, so remove it-- When you are done with it, especially if you delete or move the fileIF EXISTS(SELECT srvname from master.dbo.sysservers where srvname = @ServerName)BEGIN IF @Log = 1 PRINT 'Deleted Linked Server [email protected]+''' and Login' EXEC sp_dropserver @ServerName, 'droplogins'ENDGO