Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2001
    Posts
    135

    Unanswered: Creating a TXT file with SQL

    Hi , I am new in this group

    I have a simple question.

    How can i create a TXT file from a SQL statement?
    Something like this

    Select * from table to Txtfile

    is there any way?

    Tks

    Carlos Lages
    Rio de Janeiro

  2. #2
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    This is something I've used before for a business case that needed me to create a text file with the latest primary key (sequential ID)

    DECLARE @sCmd varchar(256)
    declare @maxid varchar(12)
    set @maxid = (select max(pk) from test_tbl)
    SET @sCmd= 'echo>c:\temp\test.txt The new Primary Key is -' + @maxid
    EXEC master..xp_cmdshell @sCmd, no_output

    You can play with this and get what you need to throw to the text file or post back if you need help.

    HTH
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  3. #3
    Join Date
    Jun 2001
    Posts
    135
    rhigdon

    tks
    i will change to my needs , but i think will work fine

    because what i realy need is select several fields from
    several tables and create a txt file.
    Carlos Lages

  4. #4
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    THis article may be of help as well

    http://www.sqlteam.com/item.asp?ItemID=4722

    HTH
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

Posting Permissions

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