Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2006
    Posts
    28

    Unanswered: how to output data into file ?

    hi, good day, can we output data from sql query into file ? for example, if i have a select sql statement which capture many records and i would like to output it into "tab" elimiter text file format

    thank in advance

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    depends. how are you executing your query? if you are using the query analyzer, you can go to the query window and choose results to file.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Jul 2006
    Posts
    28
    i need to execute it under store procedure , is it possible ?

  4. #4
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Quote Originally Posted by nakata
    i need to execute it under store procedure , is it possible ?
    yea possible,

    From command prompt:
    osql.exe -S YourServerName -U sa -P yourpassword -Q "EXEC sp_who2" -o "E:\output.txt"
    From T-SQL:
    EXEC master..xp_cmdshell 'osql.exe -S YourServerName -U sa -P yourpassword -Q "EXEC sp_who2" -o "E:\output.txt"'
    Success is the ability to go from one failure to another with no loss of enthusiasm.
    - Sir Winston Churchill
    Joydeep

  5. #5
    Join Date
    Jul 2006
    Posts
    28
    thanks rudra for information

  6. #6
    Join Date
    Apr 2005
    Posts
    22
    Fantastic solution!!!!!

    Is there any way to extend the line width so it doesn't wrap around half way through a line?

    Here's a example of my output, as you can see each line is wrapped over two:


    Compliance Documents Compliance
    Letters TOTAL
    --------------------
    -------------------- Lines in
    BatchID Filed No Image Filed No
    Image COLD File

    20060705_054203 304 0 0 1336
    1640
    20060705_054345 139 0 0 0
    139
    20060710_032623 6 0 0 0
    6
    20060710_045134 16 179 0 0
    195
    20060710_045302 0 266 0 0
    266
    20060710_064848 4041 0 16300 0
    20341
    20060710_064931 4663 0 25511 0
    30174
    20060710_065030 5145 0 89
    15747 20981
    20060710_065607 4777 13 21286 1
    26077
    20060711_091154 216 0 0 0
    216

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You could also just execute the sproc in Query Analyzer and designate a file as the output destination. QA also allows you to extend the default line width.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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