Daily CSV

  • I have been assigned a task to have a query, which a developer wrote, run against a database on a daily basis and have it generate a csv file to be placed on a network drive.

    Another tech suggested I use the xp_cmdshell to do this, but when I tried on a test server it said that the extended properties are not enabled.

    We are running SQL 2008 here

    The senior DBA suggested that we use PowerShell to do the task, but my powershell skills are not that great.

    Do you have any suggestions on how I can accomplish this job?

    Your help is appreciated

    Jeff

  • What about SSIS?

    😎

  • I would go with SSIS as well, but if you want to do it with Powershell, there are plenty of examples in the web.

    A search on google for "powershell export sql server csv" gave several posts.

    Here are some examples.

    http://poshcode.org/1662

    http://www.sqlteam.com/article/fast-csv-import-in-powershell-to-sql-server

    http://beyondrelational.com/modules/2/blogs/908/posts/18005/exporting-from-sql-server-to-csv-file-using-powershell.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks for the feedback, I will look into it.

    Jeff

  • jayoub (5/16/2014)


    I have been assigned a task to have a query, which a developer wrote, run against a database on a daily basis and have it generate a csv file to be placed on a network drive.

    Another tech suggested I use the xp_cmdshell to do this, but when I tried on a test server it said that the extended properties are not enabled.

    We are running SQL 2008 here

    The senior DBA suggested that we use PowerShell to do the task, but my powershell skills are not that great.

    Do you have any suggestions on how I can accomplish this job?

    Your help is appreciated

    What does the file have to look like? For example, should column headers be included?

    What about the data? For example, is there any possibility that the data might include a comma in it? If so, is a TAB delimited file an option?

    Last but not least, what is the end use of the data? Is it for imports to something like Excel or is it a file that will be transmitted to somewhere else?

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

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

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