Function: SQL Table Delete Records by Where Field(s)

by Simon Sparks · 4 February 2026

To use this function add it to the class library file named OrchestratorPluginSQLService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: OrchestratorPluginSQLService.ts

Description: Orchestrator Function to Delete Records by Where Field(s) in an SQL Table

Private Function: SQLTableDeleteRecordByWhereField

public SQLTableDeleteRecordByWhereField(objSQLTable: SQLTable, objPropertiesWhereField: Properties): number {

    let objSQLDatabase: SQLDatabase = objSQLTable.database as SQLDatabase;

    let strSQLQuery: string = `DELETE FROM ${objSQLTable.database.name}.${objSQLTable.name} `

    let arrKey: string[] = objPropertiesWhereField.keys;

    if (arrKey.length > 0) {
        strSQLQuery = `${strSQLQuery} WHERE`;

        arrKey.forEach((strValue: string, intIndex: number): void => {

            strSQLQuery = `${strSQLQuery} ${strValue}='${objPropertiesWhereField.get(strValue)}'`;

            if (intIndex < arrKey.length - 1) {
                strSQLQuery = `${strSQLQuery} AND `;
            }
        });
    }

    strSQLQuery = `${strSQLQuery};`

    let intQueryResult: number = this.SQLDatabaseExecuteCustomQuery(objSQLDatabase, strSQLQuery);

    return intQueryResult;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like