Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2004
    Posts
    5

    Unanswered: Reference a flat file (as a table) in a sql statemtent

    Several years ago, I am sure that I had a query that either read from or wrote to a text file. There was some way to:
    select * into 'c:\\out.txt' from SomeTable
    Does anyone know if this functionality exists? If so, what is the syntax?

    TIA

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You might be able to get what you are looking for using a text file linked server using sp_addlinkedserver (it is example H). You might also get what you want using OSQL.EXE too.

    -PatP

  3. #3
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    Originally posted by Pat Phelan
    You might be able to get what you are looking for using a text file linked server using sp_addlinkedserver (it is example H). You might also get what you want using OSQL.EXE too.

    -PatP
    Set up a linked server, then use SELECT * FROM OPENQUERY(linked_server,file) or whatever else you want to do.
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  4. #4
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    I feel OSQL is better tool to use than Linked server.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  5. #5
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    Originally posted by Satya
    I feel OSQL is better tool to use than Linked server.
    Why? And can you give the guy an example of how this would work for him, including how he'll set up the needed datasource.
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  6. #6
    Join Date
    Apr 2004
    Posts
    5
    Thanks for the replies. It doesn't look like it is possible to use the method I thought I'd remembered. Your way is more than sufficient. Thanks.

  7. #7
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    ummmm...bcp with queryout?
    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.

  8. #8
    Join Date
    Apr 2004
    Posts
    5
    Queryout? I did use bulk copy in a query to import a fixed width flat file using a format file, but I don't know what queryout is...

  9. #9
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Well I thought you're talking about outbound...

    Code:
    USE Northwind
    GO
    
    EXEC master..xp_cmdshell 'bcp "SELECT * FROM Orders" queryout c:\tax\Test.txt -S\servername\instance -U -P  -c'
    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.

Posting Permissions

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