Output to csv

  • Hi Folks

    I am trying to do a simple query and output to a csv file.

    SELECT *

    FROM mytable

    OUTPUT TO c:\mycsvfile.csv

    Could somebody please advise why this isn't working.

    I've read through loads of Forums/Suggestions, but the solutions are tooooo complicated. I want to keep it simple.

    Your help is appreciated

    Shodman

  • Hi Shodman,

    perhaps something like this, with sqlcmd:

    sqlcmd -S MyServer -E -Q"SET NOCOUNT ON SELECT * FROM

    MyTable WHERE ... " -o Result.csv

    for more information about sqlcmd read http://technet.microsoft.com/en-us/library/ms162773.aspx

    [font="Verdana"]CU
    tosc[/font]

    www.insidesql.org
  • Shodman (7/2/2008)


    Hi Folks

    I am trying to do a simple query and output to a csv file.

    SELECT *

    FROM mytable

    OUTPUT TO c:\mycsvfile.csv

    Could somebody please advise why this isn't working.

    I've read through loads of Forums/Suggestions, but the solutions are tooooo complicated. I want to keep it simple.

    Your help is appreciated

    Shodman

    OUTPUT TO is not in the T-SQL language and I don't believe it's even in DMX... You need to use one of the following...

    DTS

    SSIS

    BCP

    xp_CmdShell

    SQLCMD

    ... and they all have entries for how to use them in Books Online.

    --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)

  • Thanks for your replies Guys.

    I remebered in the end, Import/Export Wizard. It does exactly what I want!

    Thanks again

    Shodman

Viewing 4 posts - 1 through 3 (of 3 total)

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