Topic: Cross reference Members for exclusion

I have 2 tables

Members                                     Excluded
Barscan     TEXT                        ScanExcluded          TEXT
Line2         TEXT                         ReturnDate               DATE


What I wish to do is that when I press the Enter button on the form with the Barscan Input text, it will search the database in the ScanExcluded field and if the same information exists it will display the message "This person is Excluded"

Thanks for the help

Re: Cross reference Members for exclusion

Hello chrisyoco,


If you have an edit field with a barcode you just scanned in it you could do

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
    i : Integer;
    excluded_scan : String;
begin
    excluded_scan := Form1.Edit1.Text;

    i := SQLExecute('SELECT COUNT(ScanExcluded) FROM Excluded WHERE ScanExcluded = "'+excluded_scan+'"');
        if i = 0 Then ShowMessage('No result')
        else ShowMessage('This person is excluded');
end;

But why two tables ? This is doing things the hard way don't you think ? What if you want to get the name of the person whose is excluded ? You need to perform a JOIN on the first table and something like :

SELECT
Members.Line2
FROM
Members
INNER JOIN Excluded ON Members.Barscan = Excluded.ScanExcluded

What I would have built is just one table like :

CREATE TABLE "main"."member" (
"id"  INTEGER PRIMARY KEY AUTOINCREMENT,
"member_names"  TEXT,
"member_scan"  TEXT,
"is_excluded"  INTEGER NOT NULL DEFAULT 0
)

This way, each time you save a duo member / barcode, the boolean field is_excluded is set by default to 0. Set it to 1 if the code is excluded.


Or if a member can have multiple scancodes, you could create two tables :
- a member table with names, and miscellaneous info (address, date of birth...)
- a code table with a boolean field and a reference to the member table


See the attached screenshot


Hope this helped a little


Cheers


Mathias

Post's attachments

Attachment icon Capture.PNG 23.32 kb, 173 downloads since 2018-10-11 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Cross reference Members for exclusion

I tried what you posted but cant seem to get the message. I don't know what I'm doing wrong.

If it helps the scan does not return a serial number, it returns text. This is an example:

Jennifer Molina 05/16/1920

4 (edited by derek 2018-10-13 09:48:03)

Re: Cross reference Members for exclusion

Hello Chrisyoco,
Can you attach your project so we can better understand what the problem might be.
Thanks,
Derek.