Autor Beitrag
Josef-B
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Fr 02.05.03 16:34 
Hallo,

ich habe folgende SQL-Anweisung in einem IBDATASET:

Select * from Kunden where Name_1 like '%Schmidt%'

In dieser Form funktioniert es auch. Wie muss denn die Anweisung
lauten, wenn ich anstelle von Schmidt nach dem Inhalt von Edit1.Text suchen will.

Ich hab schon sovieles ausprobiert, habs aber nicht rausgekriegt. :cry:
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Fr 02.05.03 16:45 
Du musst einfach nur die Strings miteinander verknüpfen. Nur eben wegen den Hochkommata aufpassen.

ausblenden Quelltext
1:
IBQuery1.SQL.Text:='SELECT * from kunden where name_1 like '+QuotedStr('%'+Edit1.text+'%');					


So würde ich das auf jeden Fall machen.

Gruß
Josef-B Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Fr 02.05.03 17:08 
Hab ich gleich ausprobiert. Es klappt leider nicht. Fehlermeldung: unknown function quotedstr.

nur mit Select * from Kunden where Name_1 like '%' +edit1.text + '%' gehts auch nicht.

Auch .... like edit1.text geht nicht, irgendwie stimmt das was eben nicht mit den Hochkammas, oder?
kiwicht
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Fr 02.05.03 18:15 
dann versuchs mal so:

SELECT * FROM kunden WHERE name_1 LIKE ' "% ' + Edit1.Text + ' %" '

Für die Funktion "QuotedStr" müsstest du dann wohl unter "uses" eine spezielle Unit einbinden, was ansich sehr seltsam ist, weil bei mir gehts von alleine. Liegt vielleicht an deiner DelphiVersion.

Jedenfalls macht QuotedStr nicht viel mehr als vorne und hinten ein Gänsefüsschen " ranzusetzen.

(ich hoffe es war " und nicht ' :? )

mfg
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Fr 02.05.03 18:30 
Quoted String (Unit SysUtils, D6) macht noch mehr und sollte man immer nutzen.
Z.b. der String
Zitat:
Dein's oder Mein's

dort ersetzt quotedStr auch die inneren ->'<-. SOnst gibts problems bei SQL.
Ich wirds so machen:
ausblenden Quelltext
1:
2:
S:= QuotedStr('%'+Edit1.text+'%');
SQL:= format(' SELECT * FROM kunden WHERE name_1 LIKE %s ',[S]);

grez
msch
Josef-B Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Fr 02.05.03 20:40 
Jetzt hats geklappt. Ich hatte die Sql Anweisung zunächst direkt in den Objectinspector bei TIBDATASET in SelectSQL eingetragen. Da gings nicht.

Jetzt habe ich die Anweisung als Befehl unter edit1.text after exit eingegeben und es ging.

Danke an Alle.
Josef-B Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: So 04.05.03 08:34 
Und wie muss dann folgender Code lauten, wenn anstelle edit1.text eine numerische Variable stehen soll?


Code:
ausblenden Quelltext
1:
IBQuery1.SQL.Text:='SELECT * from kunden where name_1 like '+QuotedStr('%'+Edit1.text+'%');					


Ich hab schon in allen meinen Büchern etc. nachgesehen, leider nicht das
richtige gefunden.

Kann man überhaupt in einen SQL string eine numerische Variable schreiben?

Moderiert von user profile iconUGrohne: Code-Tags hinzugefügt
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: So 04.05.03 09:10 
Habe ich das richtig verstanden, das Du nach einem Integer-Feld suchen möchtest und diese nummer in Edit1 eingibst, wenn ja geht das so :

ausblenden Quelltext
1:
IBQuery1.SQL.Text:='SELECT * from kunden where name_1 like '+StrToInt(Edit1.text);					
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: So 04.05.03 10:51 
@bis11: So funktioniert das nicht, er muss einfach nur die ' im SQL weglassen, er muss die Zahl trotzdem als String hinzufügen:

ausblenden Quelltext
1:
IBQuery1.SQL.Text:='SELECT * from kunden where name_1 like '+Edit1.text;					
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: So 04.05.03 10:52 
Uups hast ja Recht. War ein Gedankenfehler von mir.
Josef-B Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: So 04.05.03 11:46 
Danke, habe aber schon das nächste Problem mit Interbase, als newbie hat man es echt nich leicht mit IB und delphi. siehe nächstes Thema.