AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Filtering two IBTable and insert or edit IBTable

Filtering two IBTable and insert or edit IBTable

Ein Thema von danten · begonnen am 28. Feb 2014 · letzter Beitrag vom 5. Mär 2014
Antwort Antwort
Seite 1 von 3  1 23   
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#1

Filtering two IBTable and insert or edit IBTable

  Alt 28. Feb 2014, 10:47
Datenbank: Firebird • Version: 2.3 • Zugriff über: 1
I need to recursively insert data from one table to another table by index (USERID =>> ID) common to both tables.
My function does not complete the operation.
Delphi-Quellcode:
function TFrm_main.Add_UserName:boolean;
var
  i:Integer;
begin
  ds_users.DataSet.First;
  for I := 0 to ds_users.DataSet.RecordCount -1 do
  begin
    Application.ProcessMessages;
    ds_attendant.DataSet.Filtered := False;
    ds_attendant.DataSet.Filter := 'USERID = '+QuotedStr(ds_users.DataSet.FieldByName('ID').Value);
    ds_attendant.DataSet.Filtered := True;
    Application.ProcessMessages;
  while not ds_attendant.DataSet.Eof do
  begin
  if (ds_attendant.DataSet.RecordCount > 0) then
  begin
    Application.ProcessMessages;
    ds_attendant.DataSet.Edit;
    ds_attendant.DataSet.FieldByName('NAME').Value := ds_users.DataSet.FieldByName('USERNAME').Value;
    ds_attendant.DataSet.Post;
    Application.ProcessMessages;
  end else
  begin
    ds_users.DataSet.Next;;
  end;
  end;
    ds_users.DataSet.Next;
  end;
  Result := True;
  ds_attendant.DataSet.Filtered := False;
end;
Daniel
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.534 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Filtering two IBTable and insert or edit IBTable

  Alt 28. Feb 2014, 11:06
This looks a little weird. Are you sure you navigate through both datasets simultaniously? Why not use SQL? Untested:
SQL-Code:
UPDATE
  ATTENDANT A
SET
  NAME = (
    SELECT
      USERNAME
    FROM
      USERS
    WHERE
      USERID = A.ID)
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#3

AW: Filtering two IBTable and insert or edit IBTable

  Alt 28. Feb 2014, 12:17
Work, thanks
update attendant a set name = (select username from users where id = a.userid)
Daniel
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#4

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 17:36
Hey, they face a new problem of filtering.
I still have the error.
Use components IBTable and join the Firebird database.
I need to filter by date.
My code:tab_attendant.Filter := 'select * from ATTENDANT where "WHEN" >= '+QuotedStr('17.2.2014 00:00:00')+' and "WHEN" < '+QuotedStr('20.2.2014 00:00:00');
Daniel
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#5

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 17:41
Why an IBTable?
The Filter attribute don't asks for a SQL statement but only the filter condition
Markus Kinzler
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#6

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 18:01
OK, does not work example:
tab_attendant.Filter := 'WHEN >= '+QuotedStr('17.2.2014 00:00:00')+' and WHEN < '+QuotedStr('20.2.2014 00:00:00');
Daniel
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 18:02
Is when a fieldname?
Is it part of the join?
Markus Kinzler

Geändert von mkinzler ( 2. Mär 2014 um 18:05 Uhr)
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#8

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 18:07
"WHEN" is FieldName.
Daniel
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.534 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 18:11
I personally prefer using queries rather than tables. Using a statement like:
SQL-Code:
SELECT
  *
FROM
  ATTENDANT
WHERE
  "WHEN" BETWEEN :start AND :end
and filling the parameters as follows:
Delphi-Quellcode:
Query.ParamByName('start').Value := EncodeDate(2014, 2 ,17);
Query.ParamByName('end').Value := EncodeDate(2014, 2, 20);
Query.Open;
should return the expected result.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#10

AW: Filtering two IBTable and insert or edit IBTable

  Alt 2. Mär 2014, 18:15
To make it more flexible ( no filter) you could extend the when condition:

SQL-Code:
WHERE
( :start is null) or ("WHEN" BETWEEN :start AND :end);
Markus Kinzler
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz