The ajDBUpdateRecord function updates records in a database table satisfying the criteria specified in filter_condition. Please take note that to run this function from Excel, you would need to set up the Data Source Connection in ##ExternalResources.
ajDBUpdateRecord( table_name, column_headers, data, [filter_type], [filter_condition], [table_schema], [data_source_id], [run_condition], [run_by_function_point_only] )
|Argument Name||Argument Type||Description|
|String||The name of the table to be updated.|
|Range / Array||The columns to be updated. It could be a range of single row or column where each cell is a table column name or a data name defined in DB Schema. CLOB and BLOB are not supported.|
|Range / Array||The range where data is located. The orientation can either be landscape or portrait. The orientation should be the same as column_headers.|
|Double||The type of filtering. 3 types are supported 0, 1 and 2. |
You need to either provide filter_type+filter_condition or the DBSchema to call this function. Otherwise, an error will be raised.
|Range / Array||The range that defines the filter condition.|
filter_type = 0. The range defines the WHERE clause of a SQL statement. The range will be concatenated into a single string. For example, Name = 'peter' and class = 'B'.
filter_type = 1. The range defines the filter condition in the Kendo grid style. Click Insert Snippet\Filter Condition (Filter Type 1) to add the preset required format.
filter_type =2. The range defines a filter condition similar to the format used in MS Query. Click Insert Snippet\Filter Condition (Filter Type 2) to add the preset required format.
Refer to the Filter Condition snippet to see how you can use this snippet to define the required fields for filter type 1, 2.
|Range / Array||The range that defines the DB Schema.|
You need to either provide the filter_type+filter_condition or the DBSchema to call this function. When DBSchema is provided, the key column(s) must be included in the Column_headers and Data. Otherwise, an error will be raised.
The data source shall be used in this database operation. It shall be defined in ##ExternalResources worksheet.The default value is "primary".
The function will run when the value is TRUE. Otherwise, it will not run.The default value is TRUE.
If it equals FALSE, the function can be executed through ‘Excel Calculation’ (can be either Automatic or Manual, Calculate Now or Calculate Sheet) or Preview Function Point.
If it equals TRUE, the function can be executed with Preview Function Point (AlchemyJ ribbon \ Preview Function Point) only.The default value is TRUE.
The function will return:
1) Return Value: Number of affected records.
2) Return Type: Single Value
We will use the following table in our examples. The table name is tb_customer. It has 5 columns and 5 rows.
Update one column of records in a table in which the Customer Level equals 5. It updates the CUSTOMER_LVL column of matched records to 99 and 1 record affected.
This example uses filter type 1 to update records where customer level equals 1 or 2.
The filter condition table was created via AlchemyJ ribbon Insert Snippet and select Filter Condition (Filter Type 1) .
This example using filter type 2 to update records where gender equals F and customer level greater than 2.
The filter condition table was created via AlchemyJ ribbon Insert Snippet and select Filter Condition (Filter Type 2) .
This example using DB Schema update records where name equals CHAN TAI MAN. The key column must be defined for filtering criteria. It can be defined in column headers or use the filter condition as Example 3.
Click here to download the use case workbooks for further reference.
It will return #VALUE! when missing any required parameter or mismatch parameter type. Besides, system will raise error for below scenario(s).
|And/Or in filter condition is invalid.|
|Column header is not a single row range or a single column range.|
|Content in filter condition range does not meet the expected format of specified filter type.|
|Data name in filter condition does not exist in the provided table schema.|
|Data name in filter condition is empty.|
|Either filter condition or table schema must be provided.|
|Invalid filter type, it must be 0, 1, or 2.|
|Invalid operator value in filter condition.|
|No Key order value defined in DB Schema.|
|Number of columns in column_headers does not match with the number of data columns.|
|Operator in filter condition is empty.|
|Table name does not exist in provided DB Schema.|
|Table name is empty.|
|The primary key value is empty.|
|The provided column header cannot be found in the specified table schema range.|
|The table schema columns are invalid.|
|The table schema range does not include a header or a row of data.|
|Total number of filter condition columns is not even number.|