November 30, 2007 at 9:40 am
I am writing a stored procedure that will invoke xp_cmdshell similiar to below:
select @cmd_str = 'bcp "select * from ...
exec @result = master..xp_cmdshell @cmd_str
I can analyze the @result variable but that only tells me if the xp_cmdshell was successful or not. It does not tell me the results of the bcp command. I'd like to retrieve the number of rows that the bcp command exported. Is there a programatic way of capturing the output from the bcp command so the number of rows that were exported can be tested?
Thanks in advance for any help you can provide.
Roy
November 30, 2007 at 12:51 pm
declare @cmd_str varchar(2000)
declare @result int
create table #t1 (info varchar(255) )
set @cmd_str = 'bcp "...." queryout ....'
insert into #t1
exec @result = master..xp_cmdshell @cmd_str
select replace(info,' rows copied.','')
from #t1
where info like '%rows copied.'
drop table #t1
* Noel
December 3, 2007 at 7:13 am
Thank you very much. This worked like a charm.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply