sau Inregistrare
  
Pagina 1 din 1
  • Nu poti crea un subiect nou
  • Nu puteti raspunde pe acest topic

DELPHI ... probleme filtrare DBF Evaluare topic: - - - - -

#1 Utilizator offline   nadu 

  • Boboc
  • Pip
  • Grup: Members
  • Mesaje: 5
  • Inregistrat: 07-July 07

Scris 07 July 2007 - 08:52 AM

Doresc sa filtrez din campul "Identif", numai inregistrarile care contin stringul din variabila varB, la prima aparitie in stringul respectiv.
Exemplu:
in campul "Identif", pot avea urmatoarele inregistrari:
A2S3 34FR445 (TR), 56DR1002 (H)
sau numai
A2 35HT677 (TR)

Codul pe care l-am realizat, filtreaza, dar nu imi ia in calcul si cel de-al doailea tip de inregistrare.
Ma intereseaza sa tina cont numai de PRIMA APARITIE a stringului dintre primele paranteze

procedure TForm1.DenTara(Sender: TObject);  
begin
  Query2.Active := True;
  Query2.First;
  varB:='';
While Not (Query2.EOF) do
begin
  if (DBLCBox1.Text = Query2.FieldByname('DENUMIRE').AsVariant) then
	 begin
	   varB:= '('+Trim(Query2['DENP'])+')';
	   Label8.Caption := 'Abreviere '+ varB;
if D1.Date > D2.Date then
	begin
	  ShowMessage('Data de inceput este mai mare decat data finala ...!');
	  exit;
	end;
 Query1.Close;
 with Query1 do
   begin
	SQL.Clear;
	SQL.Add('SELECT * FROM Table1.dbf');
	SQL.Add('WHERE Identif LIKE  ''%'+varB+'%_''');
	SQL.Add('AND Dat_cint between :Data1 and :Data2');
	SQL.Add('AND Eroare=" "');
	ParamByName('Data1').AsDate:=Self.D1.Date;
	ParamByName('Data2').AsDate:=Self.D2.Date;
	Open;
   end;
	  If Query1.RecordCount > 1 then
		 Label3.Caption:='In perioada '+DateToStr(d1.Date)+' - '+DateToStr(d2.Date)+' aveti un numar de '+ IntToStr(Query1.RecordCount)+ ' inregistrari'
	  else if Query1.RecordCount = 1 then
		 Label3.Caption:='In perioada '+DateToStr(d1.Date)+' - '+DateToStr(d2.Date)+' aveti '+ IntToStr(Query1.RecordCount)+ ' inregistrare'
	  else if Query1.RecordCount = 0 then
		 Label3.Caption:='In perioada '+DateToStr(d1.Date)+' - '+DateToStr(d2.Date)+' nu aveti inregistrari';
	   Exit;
	  end
  else
	 Query2.Next;
  end;
  
end;

Aceasta postare a fost editata de nadu: 07 July 2007 - 08:54 AM

0

#2 Utilizator offline   radu84 

  • Trandafir
  • PipPipPipPip
  • Grup: Full Members
  • Mesaje: 360
  • Inregistrat: 07-February 07

Scris 18 July 2007 - 08:27 AM

1) de ce folosesti like? tot codul asta l-ai postat doar pentru bucata de cod sql?
2) ce e cu campul ala eroare? trebuie sa fie un spatiu(' ') in cazul in care nu apare eroare?
3) " ParamByName('Data1').AsDate:=Self.D1.Date;
ParamByName('Data2').AsDate:=Self.D2.Date; " - nu am inteles rostul la asta.
4) la conditia de true pe D1.Date > D2.Date query-urile iti raman deschise

o rezolvare ar fi, sa iei intr-o variabila de tip string tot campul din tabela, si de acolo sa faci cautarea din delphi.
0

#3 Utilizator offline   nadu 

  • Boboc
  • Pip
  • Grup: Members
  • Mesaje: 5
  • Inregistrat: 07-July 07

Scris 03 August 2007 - 06:58 PM

Vezi postarearadu84, la Jul 18 2007, 09:27 AM, a spus:

1) de ce folosesti like? tot codul asta l-ai postat doar pentru bucata de cod sql?
2) ce e cu campul ala eroare? trebuie sa fie un spatiu(' ') in cazul in care nu apare eroare?
3) " ParamByName('Data1').AsDate:=Self.D1.Date;
ParamByName('Data2').AsDate:=Self.D2.Date; " - nu am inteles rostul la asta.
4) la conditia de true pe D1.Date > D2.Date query-urile iti raman deschise

o rezolvare ar fi, sa iei intr-o variabila de tip string tot campul din tabela, si de acolo sa faci cautarea din delphi.



2. In campul eroare sunt inregistrare tipul de erori, iar pe mine ma intereseaza numai inregistrarile FARA eroare.deci, numai acele campuri goale, fara a lua in calcul campurile cu erori
3. Aici vreau sa filtrez de la data pana la data.

Am rezolvat-o cam asa ...
....
begin
vt1:= '(AL)';
vt2:= '(A)';
vt3:= '(B)';
vt4:= '(BG)';
vt5:= '(BH)';
vt6:= '(BY)';
vt7:= '(CZ)';
vt8:= '(CH)';
vt9:= '(CR)';
vt10:='(CY)';
vt11:='(D)';
vt12:= '(DK)';
vt13:= '(E)';
vt14:= '(FI)';
vt15:= '(F)';
vt16:= '(UK)';
vt17:= '(GR)';
vt18:= '(H)';
vt19:= '(IE)';
vt20:='(IQ)';
vt21:='(IR)';
vt22:= '(I)';
vt23:= '(HK)';
vt24:= '(KW)';
vt25:= '(LT)';
vt26:= '(L)';
vt27:= '(MD)';
vt28:= '(MK)';
vt29:= '(NL)';
vt30:='(NO)';
vt31:='(PL)';
vt32:= '(P)';
vt33:= '(RO)';
vt34:= '(RU)';
vt35:= '(S)';
vt36:= '(SL)';
vt37:= '(SU)';
vt38:= '(SK)';
vt39:= '(SY)';
vt40:='(TR)';
vt41:='(UA)';
vt42:= '(YU)';
vt43:= '(LE)';
vt44:= '(ES)';
vt45:= '(xx)';
vt46:= '(GE)';
vt47:= '(AZ)';
vt48:= '(KG)';

Query1.Close;
 with Query1 do
   begin
	SQL.Clear;
	SQL.Add('SELECT * FROM Cantar.dbf');
	SQL.Add('WHERE (Identif NOT LIKE "%TEST%") and ((Identif LIKE "%'+vt1+'%") AND (Identif NOT LIKE "%,%") OR Identif LIKE "%'+vt1+'%_")');
	SQL.Add('AND Dat_cint between :Data1 and :Data2');
	SQL.Add('AND Eroare=" "');
	ParamByName('Data1').AsDate:=Self.D1.Date;
	ParamByName('Data2').AsDate:=Self.D2.Date;
	Open;
   end;
 vvt1:= Query1.RecordCount;

...

Aceasta postare a fost editata de nadu: 03 August 2007 - 07:01 PM

0

Reclama



Impartaseste acest subiect:


Pagina 1 din 1
  • Nu poti crea un subiect nou
  • Nu puteti raspunde pe acest topic


Subiecte similare Collapse

  Topic Deschis de Replici Vizualizari
Replici noi Atasamente imagine intr-un tabel
cum pot inregistra modifica si accesa o imagine intr-un tabel
Claudiu_k  3 2.232
Replici noi Coada- enunt problema b1a0120  1 1.965
Replici noi PROGRAM NOU
Am nevoie de exemple......
The Builder  6 6.012
Replici noi Vbs
Scuze daca nu am postat bine
WeRRoniX  1 2.527
Replici noi Manual microsoft office macro visual basic Master_Best  1 6.393