good night to all community, please I need a lot of help, I need to convert this query into a SP, several tables are being selected and I asked for a lot of help to be able to do it, now I need to convert it into a SP and then consume it I would greatly appreciate it
select nt.CUN,
rb2.IdRubro,
rb2.DescripcionRubro,
rb1.IdRubro,
rb1.DescripcionRubro,
nt.TotalMoneda1,
nt.TotalMoneda2,
cosn.IdRubro2,
cosn.DescripcionRubro2,
cosn.TotalMoneda1,
cosn.TotalMoneda2
from pwt.Nota nt
inner join pwt.CargaDetalle cd
on nt.IdCargaDetalle = cd.IdCargaDetalle
inner join pwt.Rubro rb1
on nt.IdRubro = rb1.IdRubro
inner join pwt.Rubro rb2
on cd.IdRubro = rb2.IdRubro
left join (
select csli.CUN as CUN,
cni.IdRubro as IdRubro1,
ru2.DescripcionRubro as DescripcionRubro1,
csli.IdRubro as IdRubro2,
ru1.DescripcionRubro as DescripcionRubro2,
csli.TotalMoneda1 as TotalMoneda1,
csli.TotalMoneda2 as TotalMoneda2
from pwt.ConsolidadoSubLineaIndividual csli
inner join pwt.ConsolidadoNotaIndividual cni
on csli.IdConsolidadoNo = cni.IdConsolidadoNo
inner join pwt.ConsolidadoIndividual ci
on cni.IdConsolidadoIn = ci.IdConsolidadoIn
inner join pwt.Rubro ru1
on csli.IdRubro = ru1.IdRubro
inner join pwt.Rubro ru2
on cni.IdRubro = ru2.IdRubro
where ci.IdCabecera = 928
) as cosn
on nt.IdRubro = cosn.IdRubro1
where cd.IdCabecera IN (928,929)
order by CUN