CodePudding user response:
The code is as follows:procedure TForm8. Button1Click (Sender: TObject);
The begin
DBGrid1. Visible:=true;
If radiobutton1. Checked=true then
With ADOQuery1 do
The begin
The close;
SQL. The Clear;
SQL. The add (' select a warehouse number, d. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, initial inventory, total receipts, total outbound quantity, at the beginning inventory + total receipts - total outbound quantity as current stock ');
SQL. Add (' the from (select warehouse number, a. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, the beginning inventory ');
SQL. The add (' the from steel as A inner join the beginning inventory 1 as B ');
SQL. The add (' on a. steel number=b. steel no. ');
SQL. Add (' where the warehouse number=: a and a. steel number=: b) as C inner join (select steel number, the SUM (storage quantity) as the total receipts');
SQL. The add (' the from warehouse 1 ');
SQL. The add (' group by steel number);
SQL. The add (' having steel number=: b) as D ');
SQL. The add (' on d. number=c. steel steel number inner join ');
SQL. Add (' (select steel number, the SUM (delivery) as the total outbound amount ");
SQL. The add (' 1 'from outbound);
SQL. The add (' group by steel number);
SQL. The add (' having steel number=: b) as E on d. steel number=e. steel no. ');
The Parameters. ParseSQL (SQL Text, True);
The parameters. ParamByName (' a '). The Value:=edit1. Text;
The parameters. ParamByName (' b '). The Value:=edit2. Text;
The open;
end;
If radiobutton2. Checked=true then
With ADOQuery1 do
The begin
The close;
SQL. The Clear;
SQL. The add (' select a warehouse number, d. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, initial inventory, total receipts, total outbound quantity, at the beginning inventory + total receipts - total outbound quantity as current stock ');
SQL. Add (' the from (select warehouse number, a. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, the beginning inventory ');
SQL. The add (' the from steel as A inner join beginning inventories as 2 B ');
SQL. The add (' on a. steel number=b. steel no. ');
SQL. Add (' where the warehouse number=: c and a. steel number=: d) as c inner join (select steel number, the SUM (storage quantity) as the total receipts');
SQL. The add (' the from warehousing 2 ');
SQL. The add (' group by steel number);
SQL. The add (' having steel number=: d) as d ');
SQL. The add (' on d. number=c. steel steel number inner join ');
SQL. Add (' (select steel number, the SUM (delivery) as the total outbound amount ");
SQL. The add (' the from outbound 2 ');
SQL. The add (' group by steel number);
SQL. The add (' having steel number=: d) as E on d. steel number=e. steel no. ');
The Parameters. ParseSQL (SQL Text, True);
The parameters. ParamByName (' c '). The Value:=edit1. Text;
The parameters. ParamByName (' d '). The Value:=edit2. Text;
The open;
end;
end;
CodePudding user response:
Agghh help handCodePudding user response:
Actually you use event detector tracking the Delphi generated SQL statements to understand, aren't you a, b, c, d are string type?CodePudding user response:
Add () function 2 row with no Spaces, or each of the Add () the string # 13, after you show your SQL textCodePudding user response:
Back to the third floor: yes,,,CodePudding user response:
Back: on the fourth floor, useless,,,,,,,,, but still thank you!CodePudding user response:
Don't know what's the matter, I use XE5, copy the code into, you watch ADOQuery1. SQL. The Text, you every ADD in string, so something more "# $D# $A"Suggest you directly in the connection string widestring connection is good, and then directly assigned to ADOQuery1. SQL. Text
SqlStr:='select a warehouse number, d. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, initial inventory, total receipts, total outbound quantity, the beginning inventory + total receipts - total outbound quantity as current stock';
SqlStr: SqlStr=+ 'from (select warehouse number, a. steel number, name of steel, steel specifications, unit price of steel, steel quality grades, the beginning inventory';
SqlStr: SqlStr=+ 'from steel as A inner join 1 as B' initial inventory.
SqlStr: SqlStr=+ 'on a. steel number=b. steel number'.
SqlStr: SqlStr=+ 'where the warehouse number=', '% s'' and a. steel number=', '% s'') as C inner join (select steel number, the SUM (storage quantity) as the total receipts';
SqlStr: SqlStr=+ 'from warehouse 1';
SqlStr: SqlStr=+ 'group by steel number;
SqlStr: SqlStr=+ 'having steel number=', '% s'') as D ';
SqlStr: SqlStr=+ 'on d. number=c. steel steel number inner join';
SqlStr: SqlStr=+ '(select steel number, the SUM (delivery) as the total outbound quantity';
SqlStr: SqlStr=+ '1' from outbound;
SqlStr: SqlStr=+ 'group by steel number;
SqlStr: SqlStr=+ 'having steel number=', '% s',') as on d. E steel number=e. steel number '.
SqlStr=Format (SqlStr, [edit1 Text, edit2. Text, edit2. Text, edit2. Text]);
ADOQuery1. SQL. The Clear;
ADOQuery1. SQL. Text: SqlStr=;
ADOQuery1. Open;
CodePudding user response:
To prevent the input edit1. Text, edit2. Text parameters with single quotes, it is best to format, if the parameter in single quotes, then add a single quotes, into a "'" form, otherwise, with the parameters of the single quotes will be wrong,CodePudding user response:
The parameters. ParamByName (' a '). The Value:=quotedstr (edit1. Text);
The parameters. ParamByName (' b '). The Value:=quotedstr (edit2. Text);