Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Agregar Campo Suma de una Columna a una Query?

Estimados tengo la siguiente consulta y quisiera agregar al final de la última columna la suma de 'valor de stocks'

Alguien sabe si se puede hacer? adjunto query e imagen de lo que necesito..

Saludos.

Select 'Alcapharma' 'Empresa', a.itemcode, a.itemname, d.itmsgrpnam, convert(int,a.onhand) 'Stock Total', convert(int,c.onhand) 'Biomedicals', convert(int,y.onhand) 'Pharma ISA' , convert(int,x.onhand) 'Retenidas Biomedicals', convert(int,z.onhand) 'Retenidas Pharma ISA',  convert(int,a.iscommited) 'Reservado', convert(int,(a.onhand - a.iscommited)) 'Disponible', convert(int,a.onorder) 'Solicitado', convert(int,(a.onhand + a.onorder - a.iscommited)) 'Disponible + Solicitado', a.lstevlpric, a.avgprice, a.lastpurprc, a.stockvalue

from oitm a inner join oitw b on a.itemcode = b.itemcode and b.whscode = 'b01' inner join oitw c on a.itemcode = c.itemcode and c.whscode = 'b07' inner join oitb d on a.itmsgrpcod = d.itmsgrpcod inner join oitw x on a.itemcode = x.itemcode and x.whscode = 'b04' inner join oitw y on a.itemcode = y.itemcode and y.whscode = 'b06' inner join oitw z on a.itemcode = z.itemcode and z.whscode = 'b08' 

where d.itmsgrpnam = 'Medicamentos Reg.' or d.itmsgrpnam = 'Artículo 21' and a.onhand > '0'

order by a.stockvalue desc

Former Member
replied

Hola

prueba esta consulta:

Select 'Alcapharma' 'Empresa', a.itemcode, a.itemname, d.itmsgrpnam, convert(int,a.onhand) 'Stock Total', convert(int,c.onhand) 'Biomedicals', convert(int,y.onhand) 'Pharma ISA' , convert(int,x.onhand) 'Retenidas Biomedicals', convert(int,z.onhand) 'Retenidas Pharma ISA',  convert(int,a.iscommited) 'Reservado', convert(int,(a.onhand - a.iscommited)) 'Disponible', convert(int,a.onorder) 'Solicitado', convert(int,(a.onhand + a.onorder - a.iscommited)) 'Disponible + Solicitado', a.lstevlpric, a.avgprice, a.lastpurprc, a.stockvalue from oitm a inner join oitw b on a.itemcode = b.itemcode and b.whscode = 'b01' inner join oitw c on a.itemcode = c.itemcode and c.whscode = 'b07' inner join oitb d on a.itmsgrpcod = d.itmsgrpcod inner join oitw x on a.itemcode = x.itemcode and x.whscode = 'b04' inner join oitw y on a.itemcode = y.itemcode and y.whscode = 'b06' inner join oitw z on a.itemcode = z.itemcode and z.whscode = 'b08'  where d.itmsgrpnam = 'Medicamentos Reg.' or d.itmsgrpnam = 'Artículo 21' and a.onhand > '0' union all Select '', '', '', '', null, null, null, null, null, null, null, null, null,  null, null, null, sum(a.stockvalue) from oitm a inner join oitw b on a.itemcode = b.itemcode and b.whscode = 'b01' inner join oitw c on a.itemcode = c.itemcode and c.whscode = 'b07' inner join oitb d on a.itmsgrpcod = d.itmsgrpcod inner join oitw x on a.itemcode = x.itemcode and x.whscode = 'b04' inner join oitw y on a.itemcode = y.itemcode and y.whscode = 'b06' inner join oitw z on a.itemcode = z.itemcode and z.whscode = 'b08'  where d.itmsgrpnam = 'Medicamentos Reg.' or d.itmsgrpnam = 'Artículo 21' and a.onhand > '0'

Un saludo

Agustín Marcos Cividanes

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question