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