Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    5

    Unanswered: Query output into a file

    Hi,

    In a stored procedure how do I output the result of a query to a text file?

    Regards,

    Bharathram G

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    It depends on which database engine (DB2, Microsoft, Oracle, etc) you are using, and what language was used to write the stored procedure.

    -PatP

  3. #3
    Join Date
    Feb 2006
    Posts
    5
    Hi,
    The database is SQLSERVER2000 and it uses T-SQL.
    Bharathram

  4. #4
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Quote Originally Posted by bharathram2911
    Hi,

    In a stored procedure how do I output the result of a query to a text file?

    Regards,

    Bharathram G
    T-SQL by itself has no support for saving the output of queries/stored procedures to text files. But you could achieve this using the command line utilities like isql.exe and osql.exe. You could either invoke these exe files directly from command prompt/batch files or from T-SQL using the xp_cmdshell command. Here are the examples:

    From command prompt:
    osql.exe -S YourServerName -U sa -P secretcode -Q "EXEC sp_who2" -o "E:\output.txt"

    From T-SQL:
    EXEC master..xp_cmdshell 'osql.exe -S YourServerName -U sa -P secretcode -Q "EXEC sp_who2" -o "E:\output.txt"'

    Query Analyzer lets you save the query output to text files manually. The output of stored procedures that are run as a part of a scheduled job, can also be saved to a text file.

    BCP and Data Transformation Services (DTS) let you export table data to text files.

    I hope this will clear your doubts.
    Rudra

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •