Fórum Como deletar vários registros ao mesmo tempo ? #292587

22/08/2005

0

Como deletar vários registros ao mesmo tempo? eu tenho um tabela onde os filtro são feitos po eliminação e é feito por código..vamos tupor que minha tabela tenha 5 ocorrencias com um determinado código ( código 10 por exemplo ) aí e listado somente os registros referente á ele..tem como deleter todos de uma vez ? flw..t+


Gigatel

Gigatel

Responder

Posts

22/08/2005

Rjun

Use uma instrução SQL.

DELETE FROM Tabela WHERE Codigo = 10



Responder

Gostei + 0

22/08/2005

Gigatel

Use uma instrução SQL.
DELETE FROM Tabela WHERE Codigo = 10



Olha isso..esta é minha tabela..
DELETE FROM ORCAMENTO_OFIC_ELET_ITENS WHERE Codigo = 10


dá este erro..

[Error] Unit28.pas(444): ´(´ expected but identifier ´FROM´ found


Responder

Gostei + 0

22/08/2005

Rjun

Bom, algumas perguntas:

1) Que banco você esta usando?
2) Qual a tecnologia de acesso?
3) Onde você pos essa instrução SQL?


Responder

Gostei + 0

22/08/2005

Gigatel

Bom, algumas perguntas: 1) Que banco você esta usando? 2) Qual a tecnologia de acesso? 3) Onde você pos essa instrução SQL?



1) uso interbase,
2) uso uma IBquery + IBUpdat + Datasouce
3) coloquei no botão..

desculpe num sou muito bom em sql..se vc pudesse me ajudar me mostrando o o código inteiro..

este é o nome da tabela..ORCAMENTO_OFIC_ELET_ITENS ...
este é o nome que coloquei na IBquery....BD_ORCA_ITENS....

Vlw...


Responder

Gostei + 0

22/08/2005

Rjun

Você deve colocar o código SQL no seu IBQuery. Nunca usei Interbase e nem o IBQuery. Mas acho que a ideia seria a mesma.

Crie uma Query. Vou chama-la de qryApaga. No botão, coloque o seguinte código:

qryApaga.SQL.Clear;
qryApaga.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE Codigo = ´ + IntToStr(Codigo));
qryApaga.ExecSql;


Assim, isso é uma idéia. Se alguem que manja de IB puder ajudar mais, então poste aí.


Responder

Gostei + 0

22/08/2005

Gigatel

Você deve colocar o código SQL no seu IBQuery. Nunca usei Interbase e nem o IBQuery. Mas acho que a ideia seria a mesma. Crie uma Query. Vou chama-la de qryApaga. No botão, coloque o seguinte código:
qryApaga.SQL.Clear;
qryApaga.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE Codigo = ´ + IntToStr(Codigo));
qryApaga.ExecSql;
Assim, isso é uma idéia. Se alguem que manja de IB puder ajudar mais, então poste aí.



Montei o sódigo..


BD_ORCA_ITENS.SQL.Clear;
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE Codigo = ´ + IntToStr(BD_ORCA_ITENSGS_OOEI_CODIGO));
BD_ORCA_ITENS.ExecSql;


está dando este erro....


[Error] Unit28.pas(445): There is no overloaded version of ´IntToStr´ that can be called with these arguments


Responder

Gostei + 0

22/08/2005

Gigatel

O nome da Tabela é.. ORCAMENTO_OFIC_ELET_ITENS ..
O nome do componente ( ibquery )é.. BD_ORCA_ITENS ..
O nome do campo código é ... BD_ORCA_ITENSGS_OOEI_CODIGO ...

Só para eclarecimento..


Responder

Gostei + 0

22/08/2005

Rjun

Amigo

Você esta tentando passar um TField como parâmetro em IntToStr. Coloque BD_ORCA_ITENSGS_OOEI_CODIGO.Value.

Eu evito fazer o q vc fez. Prefiro utilizar FieldByName.

BD_ORCA_ITENS.SQL.Clear; 
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE Codigo = ´ + IntToStr(BD_ORCA_ITENS.FieldByName(´GS_OOEI_CODIGO´).Value)); 
BD_ORCA_ITENS.ExecSql;



Responder

Gostei + 0

23/08/2005

Gigatel

Amigo Você esta tentando passar um TField como parâmetro em IntToStr. Coloque BD_ORCA_ITENSGS_OOEI_CODIGO.Value. Eu evito fazer o q vc fez. Prefiro utilizar FieldByName.
BD_ORCA_ITENS.SQL.Clear; 
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE Codigo = ´ + IntToStr(BD_ORCA_ITENS.FieldByName(´GS_OOEI_CODIGO´).Value)); 
BD_ORCA_ITENS.ExecSql;


o campo em questão estva errado...agora está o código com os campos certos...


BD_ORCA_ITENS.SQL.Clear;
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS  WHERE GS_OOEI_CODACES = ´ + IntToStr(BD_ORCA_ITENS.FieldByName(´GS_OOEI_CODACES´).Value));
BD_ORCA_ITENS.ExecSql;



Mas está dando este erro..

Project Teste.exe raised execption class EVariantTyeCastError..Não é possivel converter tipo de variant (null) em tipo (integer)...[/img]


Responder

Gostei + 0

23/08/2005

Imoreira

BD_ORCA_ITENS.SQL.Clear;
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS WHERE GS_OOEI_CODACES = ´ + quotedstr(BD_ORCA_ITENS.FieldByName(´GS_OOEI_CODACES´).asString));
BD_ORCA_ITENS.ExecSql;


Responder

Gostei + 0

23/08/2005

Gigatel

BD_ORCA_ITENS.SQL.Clear; BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS WHERE GS_OOEI_CODACES = ´ + quotedstr(BD_ORCA_ITENS.FieldByName(´GS_OOEI_CODACES´).asString)); BD_ORCA_ITENS.ExecSql;


Tá complicado amigo...hehehehe..tem que rir pra naum chorar...agora deu este erro..

exception class EIBInterbaseError with message..erro de conversão da string..


Responder

Gostei + 0

23/08/2005

Gandalf.nho

Faça com parâmetros que é melhor:

BD_ORCA_ITENS.SQL.Clear; 
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS WHERE GS_OOEI_CODACES = :vGS_OOEI_CODACES´);
BD_ORCA_ITENS.ParamByName(´vGS_OOEI_CODACES´).AsInteger := BD_ORCA_ITENSGS_OOEI_CODACES.Value;
BD_ORCA_ITENS.ExecSql;



Responder

Gostei + 0

23/08/2005

Jujan

IBQuery1.close;
IBQuery1.sql.clear;
IBQuery1.sql.add(´delete from <nome_da_tabela>´);
IBQuery1.sql.add(´where <nome_do_campo> like´+QuotedStr(edit1.text));
try
IBQuery1.open;
except
end;


Responder

Gostei + 0

23/08/2005

Gigatel

Faça com parâmetros que é melhor:
BD_ORCA_ITENS.SQL.Clear; 
BD_ORCA_ITENS.SQL.Add(´DELETE FROM ORCAMENTO_OFIC_ELET_ITENS WHERE GS_OOEI_CODACES = :vGS_OOEI_CODACES´);
BD_ORCA_ITENS.ParamByName(´vGS_OOEI_CODACES´).AsInteger := BD_ORCA_ITENSGS_OOEI_CODACES.Value;
BD_ORCA_ITENS.ExecSql;


Parece que está desligando a tabela e os ítens não apagam..más parou de dá erro...


Responder

Gostei + 0

23/08/2005

Gigatel

IBQuery1.close; IBQuery1.sql.clear; IBQuery1.sql.add(´delete from <nome_da_tabela>´); IBQuery1.sql.add(´where <nome_do_campo> like´+QuotedStr(edit1.text)); try IBQuery1.open; except end;


Onde este edit1 entraria na minha função...


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar