1 (edited by v_pozidis 2024-06-01 18:42:49)

Topic: How to search in script ?

Pressing the Search button, it should show, according the given name in the name box, the last name in the lastname box. Example when the name is will tha last name must be Smith. See the attached example. thank you.

Post's attachments

Attachment icon test name.zip 325.26 kb, 32 downloads since 2024-06-01 

Re: How to search in script ?

http://myvisualdatabase.com/help_en/SQLquery.html

Re: How to search in script ?

Can you be a little more specific?

I like to try some than the following script, which by the way is wrong, but I do not know how to write it

if SQLEXECUTE('select id, name, lastname from test where digit like '+Form1.edit1.text+ then form1.edit2.text := lastname);


[if the name is like the edit1 box then in the edit2 box it will get the lastname]


Thank you

Re: How to search in script ?

Hi V_Pozidis, Привіт Sparrow,
The syntax is as follows:

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
  form1.edit2.text := sqlexecute('select lastname from test where name like "%'+form1.edit1.text+'%"');
end;

But I think you are confusing 'sqlquery' with writing a procedure in a script.  'Sqlquery' will usually output to a tablegrid, not to a discrete edit field.
And I'm not sure what you are trying to achieve - what do you want to happen if you have more than one 'name' that is the same (ie Will Smith and Will Jones)?
It would make more sense, for example, to use 'Sqlquery' to output to a tablegrid all rows that have a 'name' of 'Will' and then highlight the specific row which then can fill in form1.edit2 with the 'lastname'.
Derek.

Re: How to search in script ?

Thank you Derek, you have right. I will use the table. I didn't think clear yesterday...