Topic: Complex select with variable and data

Hi guys,

I feel super dumb but I can't get my head around this very simple yet super annoying issue.

I've got this query in a script but the compiler is insulting me when I try to compile with too many arguments or the location of a ";" ,etc..

I have tried many combinations but I really miss how it should be written.

The value tPCName is retrieved from a text field in a form.

'SELECT * from Logs where Old_PC_Name='+tPCName+' or New_PC_Name='+tPCName+' and src='Computers';';   

This one is telling me the ";" is expected right before Computers like this:

'SELECT * from Logs where Old_PC_Name='+tPCName+' or New_PC_Name='+tPCName+' and src=';Computers';';

Re: Complex select with variable and data

Hi,
Try it like this
tpcname := form1.edit1.text;
sqlexecute('select fieldnames from logs where old_pc_name = "'+tpcname+'"');
.
Or don't bother with a variable and just do it direct from the text field on the form
sqlexecute('select fieldnames from logs where old_pc_name = "'+form1.edit1.text+'"');
.
Derek.

Re: Complex select with variable and data

Thanks Derek, you pointed the right thing about the variable tpcname, I was using:

tPCName := form1.edit1.sqlValue;

and it was wrong as this was retrieving an empty value returning empty results when using the proper sql query, hence my difficulties in trying to get it right by rewriting the query in many different ways!

This the working query

tPCName := Admin.EditPCName.text;

Computer_History.GridHisto.dbSQL:='SELECT * from Logs where Old_PC_Name="'+tPCName+'" or New_PC_Name="'+tPCName+'" and src="Computers"';

BUT

if I write it this way:

Computer_History.GridHisto.dbSQLExecute('SELECT * from Logs where Old_PC_Name="'+tPCName+'" or New_PC_Name="'+tPCName+'" and src="Computers"');

The compiler says: "Too many actual parameters at "356:43" (the location right behind dbSQLexecute and before opening the first parenthesis)

This is what drove me nuts in the first place!

4 (edited by sparrow 2022-08-03 17:50:48)

Re: Complex select with variable and data

Hi all,


You incorrectly used dbSQLExecute.
Form1.TableGrid1.dbSQLExecute;              // Execute an SQL query


Derek wrote in the SQLExecute example. Derek didn't know where you are using the query.
SQLExecute can return a single value and is not used for tables.

Re: Complex select with variable and data

In my opinion the theme is rather interesting. I suggest all to take part in discussion more actively.

Re: Complex select with variable and data

I suggest reading the manual first.

http://myvisualdatabase.com/help_ru/scr … egrid.html