Home > Back-end >  DELPHI SQL computing problem, please help greatly!
DELPHI SQL computing problem, please help greatly!

Time:11-12


Form called DD
Want to DBgird list below a01 + how a02 + a03 + a04 if not Chinese combined into complete item, what method to have excuse me?
Don't find many examples results, thank you greatly

Trouble for a long time!

CodePudding user response:

Try
Fieldbyname (' complete '). Asinteger:=fieldbyname (' a01). Asinteger + fieldbyname (' how a02). Asinteger + fieldbyname (' a03). Asinteger + fieldbyname (' a04). Asinteger
Except,
Fieldbyname (' complete '). Asinteger:=0;
Addition of//the number that failed, so you don't have to calculate
end;

You this question is too high, I just graduated from primary school, I do not know answer right,

CodePudding user response:

In data processing will be easier, if ADOQuery is, in the SQL processing, MSSQL can use case isnumeric (a01) when 1 then convert (int, a01) else 0 end + case isnumeric (how a02) when 1 then convert (int, how a02) else 0 end + case isnumeric (a03) when 1 then convert (int, a03) else 0 end + case isnumeric (a04) when 1 then convert (int, a04) else 0 end AS 'completed'

CodePudding user response:

reference 1st floor qq_457565758 response:
try
Fieldbyname (' complete '). Asinteger:=fieldbyname (' a01). Asinteger + fieldbyname (' how a02). Asinteger + fieldbyname (' a03). Asinteger + fieldbyname (' a04). Asinteger
Except,
Fieldbyname (' complete '). Asinteger:=0;
Addition of//the number that failed, so you don't have to calculate
end;

You this question is too high, I just graduated from primary school, I do not know answer right,



Brothers, give advice or comments please, a running error!
Where should run, or what?

CodePudding user response:

Query, and then together,

CodePudding user response:

With adoquery1 do
The begin
. Query

Try
Fieldbyname (' complete '). Asinteger:=fieldbyname (' a01). Asinteger + fieldbyname (' how a02). Asinteger + fieldbyname (' a03). Asinteger + fieldbyname (' a04). Asinteger
Except,
Fieldbyname (' complete '). Asinteger:=0;
Addition of//the number that failed, so you don't have to calculate
end;

end;//with adoquery1 do

CodePudding user response:

With adoquery1 do
The begin
If (fieldbyname (' complete '). Asinteger & lt;> 'look up a) and (fieldbyname (' complete'). Asinteger & lt;> 'procurement) then
Try
Fieldbyname (' complete '). Asinteger:
=fieldbyname (' a01). Asinteger + fieldbyname (' how a02). Asinteger + fieldbyname (' a03). Asinteger + fieldbyname (' a04). Asinteger
Except,
Fieldbyname (' complete '). Asinteger:=0;
end;
end;

CodePudding user response:


With adoquery1 do
The begin
The close;
SQL. Text:='select * from table name where ISNUMERIC (a01 + how a02 + a03 + a04) & gt; 0 '.
The open;
Try
Fieldbyname (' complete '). Asinteger:
=fieldbyname (' a01). Asinteger + fieldbyname (' how a02). Asinteger + fieldbyname (' a03). Asinteger + fieldbyname (' a04). Asinteger
Except,
Fieldbyname (' complete '). Asinteger:=0;
end;
end;

CodePudding user response:

With adoquery1 do
The begin
First;
While not Eof do
The begin
Edit;
FieldByName (' unfinished '). AsInteger:=StrToIntDef (FieldByName (' a1). AsString, 0) +
StrToIntDef (FieldByName (' a2 '). AsString, 0) +
StrToIntDef (FieldByName (' a3). AsString, 0).
Next;
end;
end;

CodePudding user response:

Code above the field name and you are on the right, should be what you want code below

With adoquery1 do
The begin
First;
While not Eof do
The begin
Edit;
FieldByName (' complete '). AsInteger:=StrToIntDef (FieldByName (' a01). AsString, 0) +
StrToIntDef (FieldByName (' how a02). AsString, 0) +
StrToIntDef (FieldByName (' a03). AsString, 0) +
StrToIntDef (FieldByName (' a04). AsString, 0).
Next;
end;
end;

CodePudding user response:

references 9 f Grefen response:
code above the field name and you do not, the following should be what you want the code

With adoquery1 do
The begin
First;
While not Eof do
The begin
Edit;
FieldByName (' complete '). AsInteger:=StrToIntDef (FieldByName (' a01). AsString, 0) +
StrToIntDef (FieldByName (' how a02). AsString, 0) +
StrToIntDef (FieldByName (' a03). AsString, 0) +
StrToIntDef (FieldByName (' a04). AsString, 0).
Next;
end;
end;


Can I ask, if is how a02 - a100 have method? Thank you very much!

CodePudding user response:

Var
I, AValue: Integer;
AFieldName, AStr: WideString;
//...//

With adoquery1 do
The begin
First;
While not Eof do
The begin
Edit;
AValue:=0;
For I:=0 to Fields. Do the Count - 1
The begin
AFieldName:=Fields [I] FieldName;
Astr:=Copy (AFieldName, 2, Length (AFieldName) - 1);
//how a02 a100 ~ ~
If (Pos (' a ', AFieldName)=1) and (StrToIntDef (Astr, 0) & gt;=2) and (StrToIntDef (Astr, 0) & lt;=100) then
AValue:=AValue + StrToIntDef (FieldByName (AFieldName). AsString, 0).
end;
If AValue & lt;> 0 then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related