generating the csv files

  • hi

    how can we generate the data in csv files of database tables by using sql query?

    regards

  • You have two options: Use OPENROWSET clause or create a Linked Server to the CSV file and insert into it like a normal table.

  • An oldie but a goodie BCP has been around for years.

    Check 'http://msdn2.microsoft.com/en-us/library/ms162802.aspx'. Unlike a lot of MS help this is pretty good and comes with lots of examples.

    One caution ... you have to mess with it a bit ... there are lots of switches!

  • Heh... I'm thinking that's more than two options right there 😉 Lets see... DTS, OSQL query, SP_OA* sprocs... there's a couple more, but I forget.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This got me thinking... I haven't seen any posts from Phil for a while.

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • I agree... he must be busy on Simple-Talk. We should pay him a visit. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I hope this isn't too simplistic, but how about just using concatenation strings? E.g.,

    SELECT Field1 + ',' + Field2 + ',' + Field3 --etc.

    From Table;

    You get rows of field data separated by commas. In SQL 2000 use DTS to take this query and put it into a Text file. I'm new to 2005 but I'm sure there's a way to accomplish the same task.

    Even simpler, just use Query Analyzer and set you output option to text (as opposed to grid) or in 2005, use the Management Studio Option for output as "Results to File".

    I'm sure you recognize that there can't be commas in the field values or this approach fails. If you know commas are present in the field values, use a different delimiter, like the pipe character (|).

    I hope I didn't misunderstand your question.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply