How to copy table content before deleting to flat file using BCP I have created stored procedure where, I delete data in any given time. I want to save the records to a flat file before deleting in case I need to import the data back to table.
I DO NOT want to call from the command line as I have a program that calls the stored procedure to schedule the job. 

CREATE PROCEDURE [dbo].[Clean] ( 
 @DeletionDate date
) AS

DECLARE @id int,
    @intError int

        DELETE FROM 
      Errn 
     WHERE 
    erid IN (
         select 
             distinct m.ID
         from 
             Member m
         left join 
             (select 
                  *, row_number() over (PARTITION BY rid order by ceid desc) 
           as rn
              from TypeA) x 
             on m.ID = x.ID and x.rn = 1
           where 
             (
                 (x.ceid is null and m.DateTime &lt; @Deletion) 

             );
     ON_ERROR:
     RETURN @intError
    RETURN 0


How can I copy the results of the select statement to a .txt file before deleting the records?
As scsimon has pointed out, you can take advantage of OUTPUT clause instead of using a flat file.

CREATE TABLE MyTable(id int identity, foo int);
CREATE TABLE MyTableDeleted(id int, foo int);

INSERT INTO MyTable VALUES
(100),(200),(300),(400),(500);




DELETE FROM
    MyTable
OUTPUT
    DELETED.* INTO MyTableDeleted
WHERE
    foo &lt;= 300;




SELECT * FROM MyTable;




id | foo
-: | --:
 4 | 400
 5 | 500



SELECT * FROM MyTableDeleted;




id | foo
-: | --:
 1 | 100
 2 | 200
 3 | 300