• Hugo Kornelis (7/28/2014)


    I realized that #Employee would not be available in the context of the bcp command, but had to do some digging to predict whether that would result in an empty file or no file.

    I guess I was lucky that the first link I found was apparently for an older version. 🙂

    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.

    Missing the behavior change is obviously another issue with the question, so I will not pound on that.

    However, to conclude on a positive note - I am happy that this question and the discussion here have made me aware of how bcp works (and has changed its behavior) when a query fails.

    Thanks, Hugo, I agree with you. Regardless of the disagreement with the question design, this is a great question to prompt review of how bcp works.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html