February 26, 2008 at 5:24 am
I've been working on creating a txt file from a proc. I've never done this from within a proc and it looks like there are a few options. SP_OACreate and OSQL. While I've been tooling around with OSQL I'm not sure it has as much functionality as SP_OACreate,SP_OAMethod etc..
I'd like to Check for file existince in a directory,Create a new file if it doesn't exist, If one does exist maybe copy or append to that file.
What would be better? OSQL or SP_OACreate?
I've dug around in BOL and have been reading about both. I have existing procs that use sp_OACreate and sp_OAMethod and I could just copy that but I would like to understand how to use it and what Methods are available. BOL doesn't seem to go that indepth about SP_OAMethod methods or much about OA_Create. Maybe I'm missing something.
Does anyone have any good links that explain this in depth?
I really hate to copy and paste to get the job done without understanding exactly what I'm doing.
TIA!
February 26, 2008 at 12:59 pm
Try something like
EXEC master..xp_cmdshell 'ECHO myMessage > C:\myFile.txt'
February 26, 2008 at 1:44 pm
Thanks for the reply.
I noticed you could create a txt file that way during my research. Problem is that's a bit to simple for what I'm trying to do. I am gathering data from multiple tables and building a body that is assigned to @Body. Something like:
select @Date from t_TableOrder where order = @OrderID
select @Customer from t_TableCustomer where order = @OrderID
SET @Body = @Date +' '+ @Customer
Only it's way more complex and uses a cursor and a nested cursor. 🙂
So I need to be able to create a file based on the data @Body is set to.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply