Sending SP output to a text file

  • We have SQL Servers: 6.5/7/2000.

    How can I issue, via SQLServereAgent scheduler, the commands "sp_helpdb, sp_helplogins, sp_helpdevice" and send the output to a textfile?


    Bill Salkin

  • you can use the osql utility

    here's a example of how to call it from Sql Server

    xp_cmdshell 'osql /U [User] /P [Password] /d [Database] /S [Server] /Q "sp_helpdb" -o C:\HelpDb.txt'

    you can schedule this as a job...

  • You could also use a DTS package to just export the tables directly. Not a "supported" technique since it references system tables, but reasonably safe in this instance.

    Yet another way would be to execute them from ADO, then you could use the recordset save method with the persist as XML option to save as XML (and transform from there if necessary to flat file) or just loop through the recordset and write it out.

    Another variation of that would be to use DMO to execute the stored proc, then run through the queryresults object and write the data out (ADO makes more sense).


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

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