I have this table from my data source Person
with multiple contact numbers:
+----------+------+------+------+------+
| NAME | con1 | con2 | con3 | con4 |
+----------+------+------+------+------+
| Jack | 123 | 3214 | 7458 | 454 |
+----------+------+------+------+------+
| Mack | 113 | 3224 | 9458 | 954 |
+----------+------+------+------+------+
| Mary | 133 | 3215 | 3458 | 054 |
+----------+------+------+------+------+
How do I validate if the string from a SLE object is already in my table?
For example: The user enters 9458
in the SLE object and clicks a button named Save
the App then tells the user that the contact number 9458
is already in the database.
I want to do this to avoid duplicates.
Solution 1: Find Duplicate Rows in Datawindow - by Expression (No SQL)
The concept is to sort data by column(s) being compared and highlighting duplicate rows using a datawindow expression (or filter). For example set the background color of a column to red on duplicate row by adding expression to the column or computed column on the background color attribute.
This is done by referring to the column name (in expression) and comparing it to the same column name with [-1] meaning the row before. Be sure to sort the datawindow first either via code or menu.
PowerScript code
Expression code
Solution 2: Find Duplicate Rows in Datawindow - by Filter (No SQL)
This is same concept as the datawindow column expression but using a datawindow filter. This makes finding the duplicates easier if there are a lot of rows to compare. Once the code is run, only rows having a duplicate will be visible all others will be filtered out of the primary datawindow buffer.
If you wanted this as part of a validation process you could put it in an event/function and prevent the save on finding duplicates.
PowerScript code
Hint: It's always a good idea to check for nulls in columns when using expressions in PowerBuilder as comparing/concatenating null values can result in unpredictable behavior.
Matt Balent's solution is perfectly fine if you want to use the database to find duplicates.