How to direct query analyzer result to a file using a command

  • Hi, We are executing sql commands/scripts thru sql query analyzer. We want to capture the query execution output to a file using sql command in the script and not by selecting on result to file option. Is there a way to achieve this ?

  • Hope this helps

    http://forums.sqlwire.com/showthread.php?t=20063

    http://www.bigresource.com/MS_SQL-Query-results-to-text-file--sxhmazqA.html#

    "Don't limit your challenges, challenge your limits"

  • you cannot do that;

    While some programs, like SQLPlus for Oracle, interpret certain commands to change the connection or to direct the input to a file, SSMS and Query Analyzer only accept the commands thru the user interface...not thru the code it is executing.

    I believe you can use osql to do that though...osql can be run from a command line, and any output cna use the standard DOS commands to send to a file, right?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • you can use BCP too.

    "Don't limit your challenges, challenge your limits"

  • Using sqlcmd would be the 2005ie way to do it. Same for 2008.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Hi,

    I hv tried sqlcmd and it seems to be more sophisticated way to do it.

    However wish it could be achieved thru query analyzer too some day.

    Thanks for your prompt inputs.:-)

  • The thing is, the query window in SSMS is for manual entry, not automation. It's unlikely they'll automate it when MS is already providing sqlcmd.exe and PowerShell scripts (another option). If you need automation, go to those utilities. When you're running stuff manually, go to the query window.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 7 posts - 1 through 6 (of 6 total)

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