Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

How to transfer the result of a consultation SQL for a matrix and a file text?

How to transfer the result of a consultation SQL for a matrix and a file text?  
 
I have a Table in Paradox with the following fields:  
 
Field      Type      Size  
Code      char      3  
Valor1      num      12  
Valor2      num      12  
Valor3      num      12  
 
With these fields, I want to generate a consultation SQL, grouped by the first digit of the field code with the totals for each digit of the fields Valor1, Valor2, Valor3. After generating the consultation, I want that these total ones are transferred for a matrix and a file text, with the accumulated values of the fields and the digit regarding these values.  
How can I make this?  
 
Thank you  
 
Gaona
0
gaona
Asked:
gaona
  • 10
  • 9
  • 2
1 Solution
 
chrismoCommented:
Can you provide some sample data and sample output? I'm not clear what you're trying to do...
0
 
gaonaAuthor Commented:
Dear Crhismo,  
 
Independently of the data that I to enter, he would like to know as to save the result of a consultation in a head office and I File text.  
 
Thankful Gaona  

0
 
gaonaAuthor Commented:
Dear Crhismo,  
 
Independently of the data that I to enter, he would like to know as to save the result of a consultation in a Matrix and I File text.  
 
Thankful Gaona  

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chrismoCommented:
Are you needing help with the SQL Statement - or with the code to output the results to a text file? What exactly do you mean by a Matrix? Do you need to display the results on a form in a grid?
0
 
ZifNabCommented:
gaona,

 ?

Just iterate through the SQL table and copy then row-by row to a text file or whatever.
Or use a batchmove, or use the ascii type of a table as output, ...

ZiF.


0
 
gaonaAuthor Commented:
Dear Crhismo and ZifNab  
 
As my English is bad, I think I didn't get myself to explain well.  
I want to save the data in an Array and a file text, so that it can use the results after the research to be done. In my case, I have to save the results of the research, to print them later.  
 
Thank you  
 
Gaona
0
 
ZifNabCommented:
gaona, I still can't see the problem about that.
An SQL gives a result, then just iterate through this SQL-table and put it in a text-file or an array like you want. Or use batchmove to transfer the results SQL table to whatever you want.
Can you give me a sort of example what you want to achive?
Zif.
0
 
gaonaAuthor Commented:
Dear Zif  
 
In my file, I have the following fields and values.  
 
Code      Val01      Val02      Val03  
7.13      150,00      100,00      70,00  
1.15       75,00       95,00      80,00  
1.12    102,00   85,00  80,00  
1.15      120,00      110,00      98,00  
7.13       65,00       80,00      75,00  
1.15      115,00      100,00 105,00  
1.12    125,00  115,00  50,00  
1.15     45,00   65,00  20,00  
 
Of this table, me that to obtain the sum of Val01, Val02, Val03 for each typed Code, separating for type of Code, that is:  
For Code 7.13, Sum_Val01=215,00; Sum_Val02=180,00 and Sum_Val03=145,00  
For Code 1.15, Sum_Val01=355,00; Sum_Val02=375,00 and Sum_Val03=303,00  
For Code 1.12, Sum_Val01=227,00; Sum_Val02=200,00 and Sum_Val03=130,00  
With these results, later on, I have to print these values added by Code and the total sum of everybody the values. For this, I elaborated a consultation SQL, containing for code and adding these values in calculated fields.  
The one that I want now, is to record the results of this consultation in an array and in a file text so that later I can print them.  
 
Thankful  
 
Gaona  

0
 
ZifNabCommented:
So you already have accomplished the result SQL (= the table which contains the values which have to be put into the array and file). Correct?
0
 
gaonaAuthor Commented:
Dear Zif  
 
Its placement is correct. The consultation was already created. The one that I need now is to record the results in an array and a file text.  
 
Thankful  
Gaona
0
 
ZifNabCommented:
what about this simple aproach :

Use TFileStream for opening your textfile... or use the AssignFile method, with Write(FType, ...);

TableValues.Open;
TableValues.First;
{open filename}
While not TableValues.EOF do begin
 Writeln(TxtFile, TableValues.FieldByName('Name').AsString
                 + '[seperator]'
                 + TableValues.FieldByName('Value').AsString
                 + ...
        )
 {put values in array }


 TableValues.Next;
end;
{close file}
TableValues.Close;


Am I still missing something?

Zif.
0
 
ZifNabCommented:
goana,

 I guess for the text-file, it can even easier!

 put a table onto form, give it as tabletype : ttASCII,

 then use a batchmove to copy the table with values to the ASCII type table.

 Use previous iteration for filling of array.

Regards, Zif.
0
 
gaonaAuthor Commented:
Dear Zif  
 
I think I didn't know how to express me right. To transfer the values of a table for an array or a file text, I already know. The one that I don't know, is to transfer the values of a consultation SQL for an array or a table.  
 
Thank you  
Gaona  

0
 
ZifNabCommented:
then i've problems... what do you mean with consultation SQL... if i may ask
0
 
gaonaAuthor Commented:
Dear Zif  
I think I am having problems in translating what I want for English. Imagine that you had a query that of that as result the sum of several fields of a table Paradox groped by a certain field (in my case a field code). It supposed that these results could not be printed directly by Quick Report in a band detail, and, that you had to record these results to print them later.  
How would you do?  
 
Thankful  
Gaona
0
 
ZifNabCommented:
... sorry still don't understand... maybe you can show me your SQL code here... maybe with one of DBDEMOS tables...
0
 
gaonaAuthor Commented:
As you asked, I created a simple form, using the table Items.db of DBDEMO in a DBGrid, according to the list below:  
 
Form1.DFM  
 
object Form1: TForm1  
  Left = 313  
  Top = 150  
  Width = 234  
  Height = 387  
  Caption = 'Form1'  
  Color = clBtnFace  
  Font.Charset = DEFAULT_CHARSET  
  Font.Color = clWindowText  
  Font.Height = -11  
  Font.Name = 'MS Sans Serif'  
  Font.Style = []  
  OldCreateOrder = False  
  PixelsPerInch = 96  
  TextHeight = 13  
  object Panel1: TPanel  
    Left = 0  
    Top = 56  
    Width = 225  
    Height = 304  
    Caption = 'Panel1'  
    TabOrder = 0  
    object DBGrid1: TDBGrid  
      Left = 1  
      Top = 1  
      Width = 224  
      Height = 302  
      DataSource = DataSource1  
      TabOrder = 0  
      TitleFont.Charset = DEFAULT_CHARSET  
      TitleFont.Color = clWindowText  
      TitleFont.Height = -11  
      TitleFont.Name = 'MS Sans Serif'  
      TitleFont.Style = []  
      Columns = < 
        item  
          Expanded = False  
          FieldName = 'OrderNo'  
          Visible = True  
        end  
        item  
          Expanded = False  
          FieldName = 'ValTot'  
          Visible = True  
        end  
        item  
          Expanded = False  
          FieldName = 'QtyTot'  
          Visible = True  
        end>  
    end  
  end  
  object BitBtn1: TBitBtn  
    Left = 128  
    Top = 16  
    Width = 75  
    Height = 25  
    Caption = 'Exec'  
    TabOrder = 1  
    OnClick = BitBtn1Click  
  end  
  object DataSource1: TDataSource  
    DataSet = Query1  
    Left = 16  
    Top = 8  
  end  
  object Query1: TQuery  
    Active = True  
    DatabaseName = 'DBDEMOS'  
    SQL.Strings = (  
      'select OrderNo, Qty*1.5 as QtyTot, PartNo as ValTot'  
      'from items.db')  
    Left = 48  
    Top = 8  
    ParamData = <> 
    object Query1OrderNo: TFloatField  
      FieldName = 'OrderNo'  
    end  
    object Query1QtyTot: TFloatField  
      FieldName = 'QtyTot'  
    end  
    object Query1ValTot: TFloatField  
      FieldName = 'ValTot'  
    end  
  end  
end  
 
Unit1.Pas  
 
unit Unit1;  
 
interface  
 
uses  
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  
  Db, DBTables, Grids, DBGrids, ExtCtrls, StdCtrls, Buttons;  
 
type  
  TForm1 = class(TForm)  
    Panel1: TPanel;  
    DBGrid1: TDBGrid;  
    DataSource1: TDataSource;  
    Query1: TQuery;  
    BitBtn1: TBitBtn;  
    Query1OrderNo: TFloatField;  
    Query1QtyTot: TFloatField;  
    Query1ValTot: TFloatField;  
    procedure BitBtn1Click(Sender: TObject);  
  private  
    { Private declarations }  
  public  
    { Public declarations }  
  end;  
 
var  
  Form1: TForm1;  
 
implementation  
 
{$R *.DFM}  
 
procedure TForm1.BitBtn1Click(Sender: TObject);  
begin  
  Query1.Active:=False;  
  Query1.Sql.Clear;  
  Query1.Sql.Add('Select OrderNo, Sum(Qty) as QtyTot, Sum(Qty*PartNo) as ValTot');  
  Query1.Sql.Add('from ''Items.db''');  
  Query1.Sql.Add('Group by OrderNo');  
  Query1.Active:=True;  
end;  
 
end.  
 
Project1.dpr  
 
program Project1;  
 
uses  
  Forms,  
  Unit1 in 'Unit1.pas' {Form1};  
 
{$R *.RES}  
 
begin  
  Application.Initialize;  
  Application.CreateForm(TForm1, Form1);  
  Application.Run;  
end.  
 
 
The one that I want to know, is as copying the data presented in DBGrid for an array and a file text.
0
 
ZifNabCommented:
well then,

why not just :


Query1.First;
{ open file here }
while not Query1.EOF do begin
 { Put here code to put data in field or array }
 {e.g.}

 Writeln(F,Query1.FieldByName('...').AsString+' '+Query1.FieldByName('..').AsString);

 Query1.Next;
end;
{ close file here }

Regards, Zif.
0
 
gaonaAuthor Commented:
Dear Ziff,  
 
Its answer was correct and it worked very well. Please tell me as doing to transfer the points of the question for you.  
 
Thankful  
 
Gaona
0
 
ZifNabCommented:
goana,

 Sorry, I forgot that I was working on this question... terrible sorry, hope you forgive me in a time.

 Are you sure everything worked or are there still some problems?

Zif.
0
 
gaonaAuthor Commented:
Dear Zif  
 
Its solution, in spite of difficult, is correct and he/she didn't leave you doubt with relationship to the operation. The one that I didn't know, is that a Query can be read as if it went a common table.  
 
Hugs  
 
Gaona
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 9
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now