Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Unanswered: SQL Server output data to text file

    I am running SQL Server 2000 and need to output query data to a text file.
    If I run the following query (Below) using XP_CMDSHELL and BCP, it runs fine and creates a text file with the data output.
    However, I need to change the WHERE Field1=10 to a string value WHERE Field1='abc'. When I try to do this I get a general error on the Field1='xyz'. I tried to change the quotes, etc but I am still getting the error. Any ideas?
    command:
    Exec master..xp_cmdshell 'bcp "SELECT Field1 FROM Table WHERE Field1=10" queryout c:\filename.txt -U UserName -P Password /S SQLServerNam /c'

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Create a view of the data that you want. Then just use xp_cmdshell to pull data from that view.
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Apr 2012
    Posts
    4

    re: create a view

    I need to use BCP to output the data to a text file so I can schedule this process on a regular basis. Can I use BCP with queryout in a SQL View on SQL Server 2000?

  4. #4
    Join Date
    Apr 2012
    Posts
    4

    re: Data output SQL Server 2000

    Thanks for the assistance. Creating a View Worked.
    I just had to ensure to change the syntax to include the Database
    DatabaseName.dbo.viewname to get it to work. Thanks!

Posting Permissions

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