Fórum Atualização de tabela complicado #57923
16/02/2007
0
Tenho que atualizar a tabela de pedidos, usando 3 tabelas:
Pedido
Item_Pedido
Moeda
Mas não to conseguindo. Tentei de duas formas usando o IBExpert:
update Item_Pedido A set DOLAR= (SELECT (A.total-(A.totalt*B.DESC/100))/ (select C.VALOR from MOEDA C where C.data=B.Pedido_data and C.INDICE=´U$´) from Item_Pedido A inner join Pedido B on B.CODIGO= A.CODIGO) where A.CODIGO>5000;
ou
update Item_Pedido A set DOLAR= (SELECT ((A.total-(A.total*B.DESC/100))/C.VALOR) from Item_Pedido A, Pedido B, Moeda C where B.CODIGO= A.CODIGO and B.data=C.data AND C.INDICE=´U$´) where A.CODIGO>5000;
Mas aparece o erro: ´multiple rows in singleton select´.
Uso Delphi7 e Firebird 1.5. Podem me ajudar? :(
Ivonei
Curtir tópico
+ 0Posts
18/02/2007
Sremulador
(SELECT (A.total-(A.totalt*B.DESC/100))/ (select C.VALOR from MOEDA C where C.data=B.Pedido_data and C.INDICE=´U$´) from Item_Pedido A inner join Pedido B on B.CODIGO= A.CODIGO)
Gostei + 0
21/02/2007
Ivonei
Aparece o mesmo erro: ´multiple rows in singleton select´. :cry:
Gostei + 0
21/02/2007
Emerson Nascimento
a falha deve estar aí. tente assim:
update Item_Pedido a set a.DOLAR = (select (a.Total - ((a.Total * b.DESC) / 100)) / c.Valor from Pedido b left join MOEDA c on (c.Data = b.Data and c.INDICE=´U$´) where b.CODIGO = a.CODIGO) where a.CODIGO > 5000
ou assim:
update Item_Pedido a set a.DOLAR = (select (ip.Total - ((ip.Total * b.DESC) / 100)) / c.VALOR from Item_Pedido ip inner join Pedido B on (b.CODIGO = ip.CODIGO) inner join Moeda c on (c.Data = b.Data and c.INDICE = ´U$´) where ip.Codigo = a.Codigo and ip.Item = a.Item) where a.CODIGO > 5000
onde [i:2aea2490ba]ip.Item[/i:2aea2490ba] deve ser o identificador único do item do pedido.
se houver um identificador único na [b:2aea2490ba]tabela[/b:2aea2490ba] de itens, aquele [i:2aea2490ba]where[/i:2aea2490ba] poderia ser simplesmente:
[i:2aea2490ba]where ip.Item = a.Item[/i:2aea2490ba]
Gostei + 0
21/02/2007
Ivonei
O update original ficou assim:
update esansi a set a.dolar= (select ((ip.totnsi-(ip.totnsi*b.pdenst)/100)-((ip.totnsi-(ip.totnsi*b.pdenst/100))*b.podnst/100))/c.valimo from esansi ip inner join esanst B on (b.npcnst = ip.npcnsi) inner join esaimo c on (c.datimo = b.datnst and c.indimo = ´U$´) where ip.npcnsi = a.npcnsi and ip.codnsi = a.codnsi) where a.npcnsi>45925
Obrigado pela ajuda pessoal :D
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)