Autor Beitrag
dinu_ch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 12.11.03 20:23 
Hallo

Ich habe eine Tabelle mit 3 Spalten :

Stichwort1
Stichwort2
Stichwort3

Der User kann im Edit-Feld den Suchbegriff angeben. Nun möchte ich, dass die Suche über alle 3 Spalten geht. Ich habs mal so probiert :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure Tanzeigen.BtnStichwortClick(Sender: TObject);
var
 estichwort : string;

begin
     estichwort:='%'+EdStichwort.Text+ '%';
     SQL_SelectString1:= (SQL_Select + ' * from dokumente.db where stichwort1 like"'+estichwort+'" ');
    SQL_SelectString2:= (SQL_Select + ' * from dokumente.db where stichwort2 like"'+estichwort+'" ');
    SQL_SelectString3:= (SQL_Select + ' * from dokumente.db where stichwort3 like"'+estichwort+'" ');
     Query1.Active:= false;
     Query1.sql.clear;
     Query1.sql.add(SQL_SelectString);
     Query1.Active:= true;

end;

Nur das funzt ned. Hat jemand eine Idee wie ich alle 3 Felder abfragen kann ?

Grüsse aus der CH

Dinu

Moderiert von user profile iconTino: Delphi-Tags ersetzt.
Horst
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mi 12.11.03 20:55 
Hallo Dinu..

Zitat:

estichwort:='%'+EdStichwort.Text+ '%';
SQL_SelectString1:= (SQL_Select + ' * from dokumente.db where stichwort1 like"'+estichwort+'" ');
SQL_SelectString2:= (SQL_Select + ' * from dokumente.db where stichwort2 like"'+estichwort+'" ');
SQL_SelectString3:= (SQL_Select + ' * from dokumente.db where stichwort3 like"'+estichwort+'" ');
Query1.Active:= false;
Query1.sql.clear;
Query1.sql.add(SQL_SelectString);
Query1.Active:= true;



wozu die Klammern um den String :?: :?:

warum machst du es nicht mit einer "oder" Abfrage, probier mal folgendes:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
estichwort:='%'+EdStichwort.Text+ '%'; 
SQL_SelectString:= 'select * from dokumente.db where stichwort1 like "'+estichwort+'" or stichwort2 like "'+estichwort+'" or stichwort3 like "'+estichwort+'"'; 
Query1.close; 
Query1.sql.clear; 
Query1.sql.add(SQL_SelectString); 
Query1.open;


funzt das :think:

Gruß

Horst
:wave:
dinu_ch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 12.11.03 21:00 
jo prima- besten dank. weisst du auch wie ich aliase für spaltennamen angeben kann ? in oracle mache ich sowas :

select name 'Name',vorname 'Vorname' etc....

und kann man die dbgrid welche die abfrage ausgibt auch verstecken wenn sie leer ist ? sieht drum ein wenig hässlich aus so leer mit einer ecke...

aber erstmals besten dank.
mstuebner
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 132

Win2000, XP
D7
BeitragVerfasst: Mi 12.11.03 23:26 
dinu_ch hat folgendes geschrieben:
jo prima- besten dank. weisst du auch wie ich aliase für spaltennamen angeben kann ? in oracle mache ich sowas :

select name 'Name',vorname 'Vorname' etc....

select name as blabla,... und Du vor allem NIEMALS ein Select * machst.

dinu_ch hat folgendes geschrieben:
und kann man die dbgrid welche die abfrage ausgibt auch verstecken wenn sie leer ist ? sieht drum ein wenig hässlich aus so leer mit einer ecke...

Wenn nix drin, dann visible:=false?

_________________
mfg Matthias
dinu_ch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Do 13.11.03 13:09 
das mit den spaltennamen hat prima geklappt.

aber wie geht das mit

visible :=false

ganz genau ?

grüsse
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Do 13.11.03 13:18 
DBGrid1.Visible := False;

Und schwupps.... war sie weg ...

_________________
Ha! Es compiliert! Wir können ausliefern!