nadu 0 Raportează post Postat Iulie 7, 2007 (editat) 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; Editat Iulie 7, 2007 de nadu Partajează acest post Link spre post Distribuie pe alte site-uri
radu84 0 Raportează post Postat Iulie 18, 2007 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. Partajează acest post Link spre post Distribuie pe alte site-uri
nadu 0 Raportează post Postat August 3, 2007 (editat) 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; ... Editat August 3, 2007 de nadu Partajează acest post Link spre post Distribuie pe alte site-uri