Fórum sql_dinamica nao esta funcionando #245493
03/08/2004
0
procedure TfrmConsulta.SpeedButton1Click(Sender: TObject);
var
tsql:string;
begin
if (length(trim(edIndice.Text)) = 0) and (length(trim(edDesc.Text)) = 0) then begin
showmessage(´Não foi selecioanda nenhuma opção para busca.´);
Status.Panels[0].Text := ´´;
SpeedButton2.Click;
end else
(*with Dm.Consulta do begin
tsql:=´select * from indice where´;
if (length(edIndice.Text) > 0) then //experimento o edIndice para saber se há algo
tsql:=tsql+´ posicao like ´+quotedstr(uppercase(edIndice.Text))+´¬´+´ and´;
if (length(edDesc.Text)) > 0 then //experimento o edDesc para saber se há algo
tsql:=tsql+´ descricao like ´+´¬´+quotedstr(uppercase(edDesc.Text))+´¬´+´ and´;
if Copy(tsql, length(tsql)-2,3) = ´and´ then
delete(tsql, length(tsql)-2,3);//removo os and não utilizados
if copy(tsql, length(tsql)-4,5) = ´where´ then //removo os wheres não utilizados
delete(tsql, length(tsql)-4,5);
Consulta.SQL.Text:=tsql;
Consulta.Active:=True; *)
end;
end;
Dá erro nos deletes: Too Many Parameters
Paulo
Curtir tópico
+ 0Posts
03/08/2004
Macario
Tente assim:
Sempre opte por usar parametros.
Qualquer coisa poste novamente
Gostei + 0
03/08/2004
Emerson Nascimento
veja se assim funciona:
var
    tsql:string;
begin
    if (length(trim(edIndice.Text)) = 0) and (length(trim(edDesc.Text)) = 0) then
    begin
        showmessage(´Não foi selecionada nenhuma opção para busca.´);
        Status.Panels[0].Text := ´´;
        SpeedButton2.Click;
    end
    else
    begin
        tsql:=´select * from indice where´;
        //experimento o edIndice para saber se há algo
        if (length(edIndice.Text) > 0) then
            tsql:=tsql+´ posicao like ´+quotedstr(uppercase(edIndice.Text)+´¬´)+´ and´;
        //experimento o edDesc para saber se há algo
        if (length(edDesc.Text)) > 0 then
            tsql:=tsql+´ descricao like ´+quotedstr(´¬´+uppercase(edDesc.Text)+´¬´)+´ and´;
        //removo o and não utilizado
        if Copy(tsql, length(tsql)-2,3) = ´and´ then
            delete(tsql, length(tsql)-2,3);
        //removo o where caso não seja utilizado
        if copy(tsql, length(tsql)-4,5) = ´where´ then
            delete(tsql, length(tsql)-4,5);
        Consulta.close;
        Consulta.SQL.Text:=tsql;
        Consulta.open;
    end;
end;
Gostei + 0
04/08/2004
Paulo
Gostei + 0
04/08/2004
Macario
Gostei + 0
04/08/2004
Emerson Nascimento
var
    tsql:string;
begin
    if (length(trim(edIndice.Text)) = 0) and (length(trim(edDesc.Text)) = 0) then
    begin
        showmessage(´Não foi selecionada nenhuma opção para busca.´);
        Status.Panels[0].Text := ´´;
        SpeedButton2.Click;
    end
    else
    begin
        tsql:=´´;
        //experimento o edIndice para saber se há algo
        if (length(edIndice.Text) > 0) then
            tsql:=tsql+´ and (posicao like ´+quotedstr(uppercase(edIndice.Text)+´¬´)+´)´;
        //experimento o edDesc para saber se há algo
        if (length(edDesc.Text)) > 0 then
            tsql:=tsql+´ and (descricao like ´+quotedstr(´¬´+uppercase(edDesc.Text)+´¬´)+´)´;
        //removo o and não utilizado
        delete(tsql, 1,4);
        if tsql <> EmptyStr then
            tsql:= ´select * from indice where´+tsql
        else
            tsql:= ´select * from indice´;
        Consulta.close;
        Consulta.SQL.Text:=tsql;
        Consulta.open;
    end;
end;
Gostei + 0
04/08/2004
Macario
Gostei + 0
04/08/2004
Emerson Nascimento
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)