Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    10

    Unanswered: Creating TXT files

    Can I use SQL Server to create a txt file on the c drive. Can sql server do nay kind of file handling. Is there a command that i can use in my background job to automatically create a txt file that will show data from a particular table.

    Never done it before .. Any ideas...

    Help is appreciated.

    Thanks

  2. #2
    Join Date
    Jan 2004
    Location
    Boston
    Posts
    58
    In the job step, choose type as OS command(CmdExec), in the command box, type:

    osql -E -Q"select top 10 * from sysobjects" -o"c:\output.txt"

    The output file is a txt format having the 10 rows in sysobjects table.

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    or bcp, dts or echo
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jan 2004
    Posts
    10
    I am using BCP and it works just fine. I get a txt file with tab seperated fields. Can i specify the character positions or lengths of each field so that all my fields line up at the same positions.

    Help is appreciated.

    I created a stored procedure with the below
    declare @filename varchar(50),
    @bcpcommand varchar(2000)

    set @filename = 'c:\report\media.txt'
    print @filename
    set @bcpcommand = 'bcp "select * from table" queryout "'+ @filename -U -P'
    exec master..xp_cmdshell @bcpCommand

Posting Permissions

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