I want to write a stored procedure that lists the name of all the servers and their corresponding databases. I know that I can use osql/sqlcmd utility to list all the servers. But 'osql -L'开发者_开发知识库 doesnot support any other parameters with it like another -Q that can list all the databases. I would want to pull both servernames and their databases using the same query. Is there a way to do it?
CREATE TABLE #servers(sname VARCHAR(255))
INSERT #servers (sname)
EXEC master..xp_CMDShell 'ISQL -L'
DELETE
FROM #servers
WHERE sname='Servers:'
OR sname IS NULL
SELECT LTRIM(sname)
FROM #servers
DROP TABLE #servers
精彩评论