Fórum SQL #350053
04/12/2007
0
E ai galera o negocio e o seguinte me ajudem por favor.
Bem tenho que fazer um Sql composto e dinamico, a medida que o usuario vai escolhendo as opções vai montando a SQL como no exemplo da foto:
[img:63fad6182b]http://i35.photobucket.com/albums/d182/kakarotossj05/consultimg.jpg[/img:63fad6182b]
´Consegui´ fazer so que fica replicando os valores, tipo eu tenho uma consutal de teste aqui, que deve retornar somente 1 registro so que esse registro retorna no DB grid +- 4 Vezes.
a seguir se encontra o codigo do botão pesquisar:
procedure TFRM_pesqucartas.Button1Click(Sender: TObject);
var
psql, aux: string;
I: integer;
begin
aux:=´´;
psql:=´Select e.Abreviatura, c.Nome_Carta, c.Poder, c.Ressitencia, c.Habilidades_Carta, c.Quantidade_Carta, c.Valor From Carta c, habilidades_carta b, habilidades h, edicao e Where c.Cod_Edicao=e.Cod_Edicao´;
//modelo padrao:
// psql:=psql+´ and (´++´)´;
if Length(edtCusto.text)>0 then
begin
aux:=ComboBox1.Items[ComboBox1.ItemIndex];
psql:=psql+´ and (c.Custo_Real´+aux+edtCusto.text+´)´;
end;
if Length(edtres.text)>0 then
begin
aux:=ComboBox2.Items[ComboBox3.ItemIndex];
psql:=psql+´ and (c.Ressitencia´+aux+edtres.text+´)´;
end;
if Length(edtpod.text)>0 then
begin
aux:=ComboBox3.Items[ComboBox3.ItemIndex];
psql:=psql+´ and (c.Poder´+aux+edtpod.text+´)´;
end;
if DBComboBox1.ItemIndex>0 then
begin
psql:=psql+´ and (c.Cod_TipoCarta=´+IntToStr(vetipo[DBComboBox1.ItemIndex])+´)´;
end;
if DBComboBox2.ItemIndex>0 then
begin
psql:=psql+´ and (c.Cod_Tribo=´+IntToStr(vetipo[DBComboBox2.ItemIndex])+´)´;
end;
if ListBox1.Items.Count>0 then //habilidade
begin
psql:=psql+´ and (c.Cod_Carta>-1´;
for I:=ListBox1.Items.Count-1 downto 0 do
if ListBox1.Selected[I] then
psql:=psql+´ or h.Cod_Habilidade=´+IntToStr(vethabili[I]);
psql:=psql+´)´;
end;
if Foil.ItemIndex=0 then
psql:=psql+´ and (c.Foil=1)´
else
psql:=psql+´ and (c.Foil=0)´;
//Inicio bloco Cor - metodo ´burro´
psql:=psql+´ and (c.Cod_Carta>-1´;
if incolor.checked then
Begin
Verde.checked:=false;
Preto.checked:=false;
Vermelho.checked:=false;
Multi.checked:=false;
Branco.checked:=false;
Azul.checked:=false;
psql:=psql+´ or c.cod_cor=6´;
end;
if verde.checked then
psql:=psql+´ or c.Custo_Carta like ´¬G¬´´; //depois do igual, colocar codigo de cada cor
// psql:=psql+´ or c.Custo_Carta like ¬G¬´;
if Azul.checked then
psql:=psql+´ or c.Custo_Carta like ´¬U¬´´;
if Preto.checked then
psql:=psql+´ or c.Custo_Carta like ´¬B¬´´;
if Branco.checked then
psql:=psql+´ or c.Custo_Carta like ´¬W¬´´;
if Vermelho.checked then
psql:=psql+´ or c.Custo_Carta like´+´´¬R¬´´;
if Multi.checked then
psql:=psql+´ or c.cod_cor=7´;
//assim vai pras outras cores
psql:=psql+´)´;
//Fim bloco cor
//Raridade, é a mesma coisa
//Inicio bloco Raridade
psql:=psql+´ and (c.Cod_Carta>-1´;
if rara.checked then
psql:=psql+´ or c.Cod_Rari=1´;
if incomun.checked then
psql:=psql+´ or c.Cod_Rari=2´;
if comun.checked then
psql:=psql+´ or c.Cod_Rari=3´;
if promocional.checked then
psql:=psql+´ or c.Cod_Rari=4´;
if bonus.checked then
psql:=psql+´ or c.Cod_Rari=5´;
psql:=psql+´)´;
//fim do sql
ShowMessage(psql);
With zqry do
Begin
Close;
Sql.Clear;
Sql.Add(psql);
Open;
end;
end;
Tipo não sei bem o que ta certo por favor se puderem me ajudar vai salvar muito.
Vlws galera .
Bem tenho que fazer um Sql composto e dinamico, a medida que o usuario vai escolhendo as opções vai montando a SQL como no exemplo da foto:
[img:63fad6182b]http://i35.photobucket.com/albums/d182/kakarotossj05/consultimg.jpg[/img:63fad6182b]
´Consegui´ fazer so que fica replicando os valores, tipo eu tenho uma consutal de teste aqui, que deve retornar somente 1 registro so que esse registro retorna no DB grid +- 4 Vezes.
a seguir se encontra o codigo do botão pesquisar:
procedure TFRM_pesqucartas.Button1Click(Sender: TObject);
var
psql, aux: string;
I: integer;
begin
aux:=´´;
psql:=´Select e.Abreviatura, c.Nome_Carta, c.Poder, c.Ressitencia, c.Habilidades_Carta, c.Quantidade_Carta, c.Valor From Carta c, habilidades_carta b, habilidades h, edicao e Where c.Cod_Edicao=e.Cod_Edicao´;
//modelo padrao:
// psql:=psql+´ and (´++´)´;
if Length(edtCusto.text)>0 then
begin
aux:=ComboBox1.Items[ComboBox1.ItemIndex];
psql:=psql+´ and (c.Custo_Real´+aux+edtCusto.text+´)´;
end;
if Length(edtres.text)>0 then
begin
aux:=ComboBox2.Items[ComboBox3.ItemIndex];
psql:=psql+´ and (c.Ressitencia´+aux+edtres.text+´)´;
end;
if Length(edtpod.text)>0 then
begin
aux:=ComboBox3.Items[ComboBox3.ItemIndex];
psql:=psql+´ and (c.Poder´+aux+edtpod.text+´)´;
end;
if DBComboBox1.ItemIndex>0 then
begin
psql:=psql+´ and (c.Cod_TipoCarta=´+IntToStr(vetipo[DBComboBox1.ItemIndex])+´)´;
end;
if DBComboBox2.ItemIndex>0 then
begin
psql:=psql+´ and (c.Cod_Tribo=´+IntToStr(vetipo[DBComboBox2.ItemIndex])+´)´;
end;
if ListBox1.Items.Count>0 then //habilidade
begin
psql:=psql+´ and (c.Cod_Carta>-1´;
for I:=ListBox1.Items.Count-1 downto 0 do
if ListBox1.Selected[I] then
psql:=psql+´ or h.Cod_Habilidade=´+IntToStr(vethabili[I]);
psql:=psql+´)´;
end;
if Foil.ItemIndex=0 then
psql:=psql+´ and (c.Foil=1)´
else
psql:=psql+´ and (c.Foil=0)´;
//Inicio bloco Cor - metodo ´burro´
psql:=psql+´ and (c.Cod_Carta>-1´;
if incolor.checked then
Begin
Verde.checked:=false;
Preto.checked:=false;
Vermelho.checked:=false;
Multi.checked:=false;
Branco.checked:=false;
Azul.checked:=false;
psql:=psql+´ or c.cod_cor=6´;
end;
if verde.checked then
psql:=psql+´ or c.Custo_Carta like ´¬G¬´´; //depois do igual, colocar codigo de cada cor
// psql:=psql+´ or c.Custo_Carta like ¬G¬´;
if Azul.checked then
psql:=psql+´ or c.Custo_Carta like ´¬U¬´´;
if Preto.checked then
psql:=psql+´ or c.Custo_Carta like ´¬B¬´´;
if Branco.checked then
psql:=psql+´ or c.Custo_Carta like ´¬W¬´´;
if Vermelho.checked then
psql:=psql+´ or c.Custo_Carta like´+´´¬R¬´´;
if Multi.checked then
psql:=psql+´ or c.cod_cor=7´;
//assim vai pras outras cores
psql:=psql+´)´;
//Fim bloco cor
//Raridade, é a mesma coisa
//Inicio bloco Raridade
psql:=psql+´ and (c.Cod_Carta>-1´;
if rara.checked then
psql:=psql+´ or c.Cod_Rari=1´;
if incomun.checked then
psql:=psql+´ or c.Cod_Rari=2´;
if comun.checked then
psql:=psql+´ or c.Cod_Rari=3´;
if promocional.checked then
psql:=psql+´ or c.Cod_Rari=4´;
if bonus.checked then
psql:=psql+´ or c.Cod_Rari=5´;
psql:=psql+´)´;
//fim do sql
ShowMessage(psql);
With zqry do
Begin
Close;
Sql.Clear;
Sql.Add(psql);
Open;
end;
end;
Tipo não sei bem o que ta certo por favor se puderem me ajudar vai salvar muito.
Vlws galera .
Robo
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)