If you've ever wanted to BCP from inside a stored procedure here's how:
DECLARE @FileName varchar(50) ,@bcpCommand varchar(2000) ,@YearMonth char(7)
set @YearMonth = '2006-04'SET @FileName = '\\server\share\folder\'+ @YearMonth +'.txt'
SET @bcpCommand = 'bcp "SELECT * FROM Northwind..tblSomeTable where SomeField like ''' + @YearMonth + '%''" queryout "'SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P password -c'
print @bcpCommandExec master..xp_cmdshell @bcpCommand
Notice that in this example the BCP is using an sql query to filter the exported records. Also notice that I am using the same filter as the name of the exported file.