Results 1 to 2 of 2

Thread: SQL output

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    SQL output

    hi,

    can i direct my sql statement output directly to any text file??

    like: db.execute("selecte * from table1")

    i want the output of the statement in a text file. i dont want to loop it across.

    is it possible??

    regards

  2. #2
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279
    If you mean write the results of a query to a text file, yes you can. One example I could offer is selecting a string from a temporary table. Within the context of a stored procedure you could do this:

    Declared at top of stored procedure:
    @FilePath varchar(128),
    @cmdString varchar(256)


    In the body of the procedure:

    Set @FilePath='C:\MyFolder\MyFile.txt'

    Set @cmdstring='bcp "Select TransString from ##TempTable"' +
    ' queryout ' + @FilePath + ' -c -S' + @@ServerName + ' -Usa -P'

    Or you substitute the above line with:

    Set @cmdstring='bcp ##DailyTable' + ' out ' +
    @FilePath + ' -c -S' + @@ServerName + ' -Usa -P'

    This would just copy the whole temporary table to the text file.
    And then...

    Execute master..xp_cmdshell @cmdstring

    In this example your username is 'sa' and password is blank. For more detail check out the bulk copy (bcp) info in the help file.
    Last edited by Dman; Mar 2nd, 2004 at 06:11 PM.
    A cynic knows the price of everything but the value of nothing.

Posting Permissions

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



Click Here to Expand Forum to Full Width