Remove Records from DB Table Using Stored Procedure Before Data Extraction
Perform the following generic steps to clear existing records in Database table using Stored Procedure before Data Extraction.
- Open Process Runner DB file that you have created and connect to DataSource.
- Go to SQL Management studio, right-click on the database that you are connected via Process Runner DB and select New Query.
- Enter the following code and press execute, replace DBName with Database name from the below code.
USE [DBName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[TruncateTable]
-- Add the parameters for the stored procedure here
@TableName varchar(50)
AS
BEGIN
Declare @sql as varchar(200)
set @sql = 'TRUNCATE TABLE ' + @TableName
exec(@sql)
END
GO - It creates a stored procedure under the database » <Your Database Name> » Programmability.
In the below image, the Database name is PurchaseReq.
- Go back to Process Runner DB and select Edit tab > Script and Delays Options > Pre Script.
- In the Pre-Run/Post-Run Process Settings window, select the Pre-Run Process checkbox.
- Select Stored Procedure from drop-down menu.
- Select TruncateTable from drop-down list of Stored Procedures and select OK.
- In this same window, provide the table name in Parameter Value column. The table name should be exactly same which is mapped in the Process file.
- Select OK and save the Process file.