How to return SP or query data to a Text File

  • What is the best way to create a proc that takes in a 'Path' parameter and then dumps the result of the proc (which is just a select stmt) to a file based in the passed in path?

    I guess I can use OSQL and then use the -o but wanted to avoid using it. Is there another way.

    Thanks,

    Daniel

  • I have used the sp_OA procedures to create and use instances of the File System Object found in scrrun.dll, but these are fraught with security implications and take a lot of server time, and should be used with great care, and only where absolutely required. The only reason I used them like this was because it is inside a trigger that is the focal point of several applications, and I have secured the access pretty well. I am currently looking to get away from this method, FWIW. My feeling on this is to let the application deal with files - your db server's time is too valuable and there not a lot of native ways to do it...

  • For a simple query you could also use bcp


    * Noel

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

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