sorry for the delay as i am not in town.
below is the code snippet. on an average this cursor has to generate around 90 files and this cursor runs every 15min.
----------------------------------------
declare my_cursor CURSOR for
select distinct WRS.f1 , WRS.c1 from tab2 WCB
inner join tab1 WRS on WCB.c1=WRS.c1
OPEN my_cursor
FETCH NEXT FROM my_cursor
INTO @f1, @c1
WHILE @@FETCH_STATUS = 0
BEGIN
set @nvchProcedure = 'proc name'
select @ts = convert(varchar, getdate(),112)+replace(convert(varchar, getdate(),108),':','') -- suffix the file name with datetimestamp
select @ff1 = @f1 + @ts + '.psv'
insert into tab3 (c1,f1,ff1)values (@c1,@f1,@ff1)
SELECT @cmd = 'osql -S ' + @@servername +' -E -n -h-1 -w2500 -q "SET NOCOUNT ON EXEC ' + @HostDB + '.dbo.' + @nvchProcedure +' '''+@c1 +''''+',''''+'" -o "'+ @nvchFileLocation +@f1+@ts+'.psv'
EXEC master..xp_cmdshell @cmd
FETCH NEXT FROM my_cursor
INTO @f1, @c1
END
CLOSE my_cursor
DEALLOCATE my_cursor
----------------------------------------