var onay,medeni,cinsiyet,erkek,bayan,bekar,evli,dul,bosanmis,onaylandi,arastirmada,rededildi:String;
begin
erkek:=CheckBox1.Caption;
bayan:= CheckBox2.Caption;
bekar:=CheckBox3.Caption;
evli:=CheckBox4.Caption;
dul:= CheckBox6.Caption;
bosanmis:=CheckBox5.Caption;
onaylandi:=CheckBox7.Caption;
arastirmada:=CheckBox8.Caption;
rededildi:=CheckBox9.Caption;
ADOQuery1.SQL.Clear;
if CheckBox1.Checked=true then cinsiyet:=' and cinsiyet = '''+erkek +'''' ;
if CheckBox2.Checked=true then cinsiyet:=' and cinsiyet = '''+bayan +'''' ;
if CheckBox1.Checked=true and CheckBox2.Checked=true then cinsiyet:='';
if CheckBox3.Checked=true then medeni:=' and medenihali = '''+bekar +'''' ;
if CheckBox4.Checked=true then medeni:=' and medenihali = '''+evli +'''' ;
if CheckBox5.Checked=true then medeni:=' and medenihali = '''+bosanmis +'''' ;
if CheckBox6.Checked=true then medeni:=' and medenihali = '''+dul +'''' ;
if CheckBox3.Checked=true and CheckBox4.Checked=true and CheckBox5.Checked=true and CheckBox6.Checked=true then medeni:='';
if CheckBox7.Checked=true then onay:=' and onaydurumu = '''+onaylandi +'''' ;
if CheckBox8.Checked=true then onay:=' and onaydurumu = '''+arastirmada +'''' ;
if CheckBox9.Checked=true then onay:=' and onaydurumu = '''+rededildi +'''' ;
if CheckBox7.Checked=true and CheckBox8.Checked=true and CheckBox9.Checked=true then onay:='';
ADOQuery1.sql.Add('select * from genelbilgileri where 1=1'+cinsiyet+medeni+onay);
ADOQuery1.Open;
end;
yukarıdaki kod ile birden çok alanla sorgu yapmak istiyorum ama doğru çalışmadı.
onaylanan seçeneklere göre arama yapmıyor onay dışı seçeneklerde listeleniyor. Yardım edecek varmı acaba teşekkürler
SQL birden çok alanda arama
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
Re: SQL birden çok alanda arama
Kod: Tümünü seç
sql:='select * from genelbilgileri';
and:=' where ';
if CheckBox1.Checked=true then
sql:=sql+and+'cinsiyet = '''+erkek +'''' ;
and:= ' and ';
endif
if CheckBox2.Checked=true then
sql := sql +and+ 'cinsiyet = '''+bayan +'''' ;
and:= ' and ';
endif
...
....
ADOQuery1.sql.Add(sql);
-
- Üye
- Mesajlar: 9
- Kayıt: 25 Nis 2006 10:49
Re: SQL birden çok alanda arama
Yazdığın kodlarla denedim ama yine istediğim gibi çalışmadı. Aynı anda Erkek ve Bayan onaylayınca sorgu boş çıkıyor. Sorunu çözemedim.
- sabanakman
- Kıdemli Üye
- Mesajlar: 3081
- Kayıt: 17 Nis 2006 08:11
- Konum: Ah bi Antalya olaydı keşke (Ankara)
Re: SQL birden çok alanda arama
O zaman and yerine or şartı kullanmalısınız.
Şaban Şahin AKMAN
_________________
Derin olan kuyu değil kısa olan iptir. - .
_________________
Derin olan kuyu değil kısa olan iptir. - .