Home > Back-end >  DELPHI is used in a SELECT statement, how to add variables before the WHERE
DELPHI is used in a SELECT statement, how to add variables before the WHERE

Time:10-11

Mform1. ADOQuery2. SQL. The Add (' SELECT ');
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - 1000 production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours from crpda where WKCL=: Sname and wksta>=: st and wksta<=: en group by wkptimere ');
Mform1. Adoquery2. The Parameters. ParamByName (' Sname). Value:=cl;
Mform1. Adoquery2. The Parameters. ParamByName (" St "). The Value:=strtoint (edit1. Text);
Mform1. Adoquery2. The Parameters. ParamByName (' en '). The Value:=strtoint (edit2. Text);
Mform1. ADOQuery2. Open;
Mform1. Adoquery2. ExecSQL;
Is statement code above, in the statement above SUM (wkptimere) - 1000 this format, numerical is right, but I want to send 1000 as a variable exists, as long as 1000 as a variable query result is empty,
Have done the test including
The SUM (wkptimere) - : gs
Mform1. Adoquery2. The Parameters. ParamByName (" gs "). The Value:=1000;
And define the SQL variable
Mform1. ADOQuery2. SQL. The Add (' DECLARE @ zz float ');
Mform1. ADOQuery2. SQL. The Add (' SET @ zz=1000 ');
The SUM (wkptimere) - @ zz
The query result is empty, two methods mentioned above, for help if you let 1000 as a random variable assignment

CodePudding user response:

 
Var bl integer;
Bl:=1000;
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - '+ inttostr (bl) +' production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours

CodePudding user response:

reference 1st floor yangsh0722 response:
 
Var bl integer;
Bl:=1000;
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - '+ inttostr (bl) +' production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours


Inttostr (bl), is the type of this problematic wkptimere FOLAT, no need to convert character
Cannot execute the statement

CodePudding user response:

reference 1st floor yangsh0722 response:
 
Var bl integer;
Bl:=1000;
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - '+ inttostr (bl) +' production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours


Can be carried out but the result is empty,, but the SUM (wkptimere) - 1000 when the result is correct

CodePudding user response:

refer to the second floor xuewuchen response:
Quote: refer to 1st floor yangsh0722 response:

 
Var bl integer;
Bl:=1000;
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - '+ inttostr (bl) +' production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours


Inttostr (bl), is the type of this problematic wkptimere FOLAT, no need to convert character
Unable to perform this statement

'the SUM (wkptimere) -' this is a string string form?
At the back of the 'production capacity, the sum (wkptime) plan working hours, the sum (wkovt)... 'is the string form of the string
String links, so want to convert an integer or float to the string!

CodePudding user response:

What other wrong you

CodePudding user response:

reference 4 floor yangsh0722 response:
Quote: refer to the second floor xuewuchen response:

Quote: refer to 1st floor yangsh0722 response:

 
Var bl integer;
Bl:=1000;
Mform1. ADOQuery2. SQL. Add (' SUM (wkptimere) - '+ inttostr (bl) +' production capacity, the SUM (wkptime) plan working hours, the SUM (wkovt) overtime working hours


Inttostr (bl), is the type of this problematic wkptimere FOLAT, no need to convert character
Unable to perform this statement

'the SUM (wkptimere) -' this is a string string form?
At the back of the 'production capacity, the sum (wkptime) plan working hours, the sum (wkovt)... 'is the string form of the string
String links, so want to convert an integer or float to the string!


These fields are float type, right here, all the statements, timely perform only SUM (wkptimere) - 1000, this is not the result, I have the feeling that is the problem here

CodePudding user response:

Problem has been resolved, and posted, knot, posted solutions
Mform1. ADOQuery2. SQL. The Add (' SELECT ');
Mform1. ADOQuery2. SQL. The Add (Format (' SUM (wkptimere) - % d capacity, 'and [bl]));
Mform1. ADOQuery2. SQL. Add (' sum (wkptime) plan working hours, the sum (wkovt) overtime working hours from crpda where WKCL=: Sname and wksta>=: st and wksta<=: en group by wkptimere ');
//Mform1 adoquery2. The Parameters. ParamByName (" gs "). The Value:=1000;
Mform1. Adoquery2. The Parameters. ParamByName (' Sname). Value:=cl;
Mform1. Adoquery2. The Parameters. ParamByName (" St "). The Value:=strtoint (edit1. Text);
Mform1. Adoquery2. The Parameters. ParamByName (' en '). The Value:=strtoint (edit2. Text);
Mform1. ADOQuery2. Open;
Mform1. Adoquery2. ExecSQL;

The key is to use the FORMAT the FORMAT

CodePudding user response:

 

Try
Var
SQLSTR: string;
SQLSTR:='SUM (wkptimere) - 1000 as production capacity, the SUM (wkptime) as plan working hours, the SUM (wkovt) as overtime working hours from crpda where WKCL=';
SQLSTR: SQLSTR=+ + cl + ' ' ' ' ' ' ' '+' and wksta>='+' "' + edit1. Text + ' ' ' '+' and wksta<='+' ' ' 'the + + edit2' ' ' '+' group by wkptimere ';
Adoquery2. Close;
Adoquery2. SQL. The clear;
Adoquery2. SQL. The add (SQLSTR);
Adoquery2. Open;

This passage above is my own beating might be wrong, change yourself, don't use insert passed, difficult with death,

CodePudding user response:

 
Var
SQLSTR: string;
SQLSTR:='select SUM (wkptimere) - 1000 as production capacity, the SUM (wkptime) as plan working hours, the SUM (wkovt) as overtime working hours from crpda where WKCL=';
SQLSTR: SQLSTR=+ + cl + ' ' ' ' ' ' ' '+' and wksta>='+' "' + edit1. Text + ' ' ' '+' and wksta<='+' ' ' 'the + + edit2' ' ' '+' group by wkptimere ';
nullnullnullnullnullnullnull
  • Related