Esto es un procedimiento que intento hacer para una aplicacion que por algun error me genera documentos dobles y necesito eliminarlos todos.
Código SQL
[-]craate procedure EliminaDocumentoGeneradosDobles
@FactNo varchar(30)
as
declare
@FactId int,
@FDet int
--para saber el idfactura conociendo su numero
select @FactId = idfactura from fac_factura
where NumCons = @FactNo
--para saber el iddetalle conociendo su idfactura
select @FDet = iddetalle from Fac_DetalleB
where idfactura = @FactId
begin tran
delete from Fac_DetalleBS
where iddetalle = @FDet
delete from Fac_DetalleB
where idfactura = @FactId
if @@error <> 0
begin
RollBack
raiserror ( 'Error al eliminar factura.', 16, -1)
end
else
Commit
Por eso es que intentaba buscar otra solución tal como:
Código SQL
[-]delete from Fac_DetalleBS
where iddetalle = (select iddetalle from Fac_DetalleB
where idfactura = 15361)
No se si me hago entender.