0
I need to make a update update the field record of a table, using another record of the same table and same field. My table is as follows:
select produto,valor_bruto,acrescimo,valor_liquido
from tab_itens
where data='2021-06-10'
and caixa=8
and cupom in (145,146)
In coupon 145, the values of the fields "raw value", "accrescimo" and "liquid value" are correct, however, in coupon 146 which is a double sale, the values of the fields "accrescimo" and "liquid value" were wrong.
I tried the following query:
update tab_itens set
acrescimo=(select acrescimo
from tab_itens
where cast(data as date)='2021-06-10'
and caixa=8
and cupom=145)
where cast(data as date)='2021-06-10'
and caixa=8
and cupom=146;
The result of sql server was:
Message 512, Level 16, Status 1, Line 10 Sub-volume returned more of 1 value. This is not allowed when the sub-consumption follows =, != , <, <= , >, >= or when it is used as an expression.
How do I update the fields "accrescimo" and "valor_bruto" of coupon 146, using the same fields only of coupon 145?
What is the structure of the table
tab_itens
?– Clarck Maciel
Clarck, the whole structure?
– Rody M. Good
It can only be with the main fields, mainly with the key fields of the table and the fields involved in the update operation.
– Clarck Maciel