I want to update each corresponding column in SQL if the retrieved field values are not null. Is there a way using Update Query to only update the field if not null. I am hoping I do not have to do a conditional sequence for 'not null' on every retrieved value before the Update Query? Thanks in advance.
Question
Question
Replies
Hi Bonnie,
Which database are you updating? Altering Repository databases through workflow is generally not supported because it can cause irreparable damage if done incorrectly.
If you are updating External Tables (it sounds like you are), I would recommend using a Custom Query. I have written an example query and I will walk you through it.
You retrieve field values and some of them are blank (Column2 and Column4):
(Figure 1)
You now want Workflow to update a SQL table, called "Table_Name", with the above field values. You only want the field values that are NOT blank to update SQL.
In your Workflow, you retrieve the field values, and then create a Custom Query:
(Figure 2)
The SQL code can be seen more clearly here:
UPDATE Table_Name SET Column1 = ISNULL(NULLIF(?, ''), Column1), Column2 = ISNULL(NULLIF(?, ''), Column2), Column3 = ISNULL(NULLIF(?, ''), Column3), Column4 = ISNULL(NULLIF(?, ''), Column4) WHERE Criteria_Column1 = ? AND Criteria_Column2 = ?;
Going through the code:
Table_Name is the table you're updating. Below SET, Column1 through Column4 are the names of the columns you want to update. Criteria_Column1 and Criteria_Column2 are the names of the columns that match your criteria (First Name and Last Name, for example).
The question marks are place holders for your field values, and are read top-down. This means the first question mark in the code is matched up with first question mark in your Parameter Names (Figure 2). These parameters names have Parameter Values (Figure 2) that are set with tokens made by the Retrieve Field Values tool.
Here is a test to show how this Custom Query acts on a table:
The Custom Query updated the table with only field values that were NOT empty (Figure 1), and left the other columns alone.
Please let me know if you need help configuring this to your system.
I believe there is not a way but I'd love this to be a feature request!!! (Maybe a checkbox next to each field that says "ignore if data is null?")
I'm always running into this situation with dates in particular.
Plus it would be faster if there was no need to use multiple, separate update queries for the same entry.