• Hugo Kornelis (7/28/2014)


    ...I then tried running it and found that I had to make a lot of code changes to even get it to work. I had to fix the inconsistent upper- and lower-case use (not everyone uses case insensitive collations, you know!), and then had to add the -S option to bcp (not everyone is running a default instance, you know!).

    And then I also had to create a folder Exports in the C: root before I could finally run the script.

    It's a bit sad that the author explicitly called out one assumption (xp_cmdshell enabled), but failed to mention all the above.

    Thanks for saying it so I could simply copy and paste...I too ran into the -S and missing folder issues.

    Yes, a silver lining, learning about a difference in bcp behavior from version to version. It surely is a pity that xp_cmdshell had to be a part of the learning process, and yet with no mention that xp_cmdshell is disabled by default in the product due to pervasive security concerns, the question and the presumed path many took in trying to run the code could only promote the idea that this technique is a safe and secure way to get data out of SQL Server, which it surely is not. Leave xp_cmdshell alone and pickup SSIS or invoke bcp.exe from an application server's command-line instead of from within a T-SQL process.

    Thanks for posting the question.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato