SQL Query

SQL Query

Toto je ukážka z môjho programovania s využitím SQL jazyka v Delphi

Datamodule2.Zisti_data.SQL.Clear;
Datamodule2.Zisti_data.SQL.Text:='CREATE TABLE "SNV_Vars_3.db"(Ico CHAR(20),Vars CHAR(20),Suma NUMERIC(10,4))';
Datamodule2.Zisti_data.ExecSQL;
Datamodule2.Zisti_data.SQL.Clear;
Datamodule2.Zisti_data.SQL.Text:='Insert into "SNV_Vars_3.db" select * from SNV_vars';
Datamodule2.Zisti_data.ExecSQL;
Datamodule2.Zisti_data.SQL.Clear;
Datamodule2.Zisti_data.SQL.Text:='Delete from SNV_Vars_3 where ico not in (select ico from SNV_vars group by ico having (count(ico) ="3"))';
Datamodule2.Zisti_data.ExecSQL;
Datamodule2.Zisti_data.SQL.Clear;
Datamodule2.Zisti_data.SQL.Text:='Create index ico on "SNV_Vars_3.db" (ico)';
Datamodule2.Zisti_data.ExecSQL;

Datamodule2.Query1.Active:=false;
Datamodule2.Query1.SQL.Clear;
Datamodule2.Query1.SQL.Text:='Select count(ico) from SNV_Vars_3';
Datamodule2.Query1.ExecSQL;
Datamodule2.Query1.Active:=true;
pocet_zaz1:=StrToInt(Datamodule2.Query1.FieldValues['COUNT OF ico']);
pocet_zaz2:=pocet_zaz1/3;
pocet_zaz3:=FloattoStr(pocet_zaz2);
pocet_zaz1:=StrToInt(pocet_zaz3);

Datamodule2.Zisti_data.Active:=false;
Datamodule2.Zisti_data.SQL.Clear;
Datamodule2.Zisti_data.SQL.Text:='Select Ico,vars,suma from SNV_Vars_3';
Datamodule2.Zisti_data.ExecSQL;
Datamodule2.Zisti_data.Active:=true;

Datamodule2.Zisti_data.First;
for i:=1 to pocet_zaz1 do begin
 ico:=Datamodule2.Zisti_data.FieldValues['Ico'];
 vars:=Datamodule2.Zisti_data.FieldValues['vars'];
 Suma:=Datamodule2.Zisti_data.FieldValues['suma'];
 Datamodule2.Insert.SQL.Clear;
 Datamodule2.Insert.SQL.Text:='Update SNV_Vars_All set Vars_1="' + vars + '",suma_1="' + suma + '" where ico="' + ico + '"';
 Datamodule2.Insert.ExecSQL;