How do I send query output to a file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wallacee
    New Member
    • Sep 2006
    • 2

    How do I send query output to a file?

    Five year PL/SQL programmer with a MSSQL question. I need to spool (the PL/SQL verb) output to a file from an MSSQL statement.

    In PL/SQL it would look like:

    spool myoutput.txt
    select table_name from all_tables
    spool off

    How do I do this in MSSQL?

    Thanks,

    Eric
  • ERInfo
    New Member
    • Oct 2006
    • 1

    #2
    You can run this from a windows command prompt or a batch file:

    osql -Usa -Pmypassword -dmydatabase -Smyservername -Q"select table_name from all_tables" -o c:\sqlout.txt

    Just replace mypassword with your password, mydatabase with the correct database name, and myservername with the name of your server or (local) if your running the command on the server.
    Hope this helps

    Comment

    Working...