October 6, 2009 at 2:27 pm
I am using BCP with a stored procedure to output the results to a text file. I need to run this daily but would like no file created if the procedure returns no results.
My BCP command is:
declare @filename varchar(30)
declare @sql varchar(200)
select @filename = 'MyFile_' + convert(char(8),getDate(),112) + '.csv'
select @sql = 'bcp "exec [MyData].[dbo].[MySproc]" queryout \\server\sharename\' + @filename + ' -c -t, -T'
exec master..xp_cmdshell @sql
If the proc returns no results, this still creates a 0 byte file.
Thanks
July 25, 2012 at 2:13 am
Love it when you have a problem, find someone with the same issue, and no solution.
🙂
Oh well..
Will keep looking...
July 25, 2012 at 11:53 am
I think what I ended up doing was using a simple select statement to find if the proc would return any results then if it did not, the proc was not run.
The proc was to export orders to a file so it was a simple select to find if I had any orders to export first.
July 25, 2012 at 1:34 pm
Nice simple solution.
Thanks for that... will be useful.
Thanks again.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply