Good morning, in a trigger for insert I need to delete all the records that have a value greater than 0 in vat and at the same time delete one that does not say vat of the same client and same rut. (Does not have primary key)
EJ:
Cliente | rut | precio | ganado | iva | fecha ────────┼────────────┼────────┼────────┼────────┼───────── Diego | 23423333-3 | 345344 | 345344 | 0 | 20160111 Diego | 23423333-3 | 345344 | 345344 | 0 | 20160111 Diego | 23423333-3 | 345344 | 345344 | 0 | 20160111 Diego | 23423333-3 | 345344 | 0 | 345344 | 20160111
delete top (
SELECT COUNT(*)
FROM [dbo] as f
inner join inserted as d on (d.rut=f.rut)
Where f.ganado in(select iva from Inserted) and f.nombre=d.nombre and d.fecha=f.fecha
)
from [dbo]
from [dbo] as f
inner join inserted as d on (d.rut=f.rut)
Where f.ganado in(select iva from Inserted) and f.nombre=d.nombre and d.fecha=f.fecha
SHOULD: Delete the row with VAT and one with same rut, name date and price won.
EJ:
Cliente | rut | precio | ganado | iva | fecha ────────┼────────────┼────────┼────────┼─────┼───────── Diego | 23423333-3 | 345344 | 345344 | 0 | 20160111 Diego | 23423333-3 | 345344 | 345344 | 0 | 20160111
But it only eliminates value without iva, leaving the records gained without eliminating them (from 1 to 1).
Thank you very much already.