ALTER PROCEDURE [dbo].[sp_venDetalle]
(
@coddoc int,
@grudoc int,
@numinv BIGINT
)	
AS 
SELECT     
D.numlin,
D.codbus,
D.nomart,
U.abruni,
D.cantidad, 
--D.unialt,
D.canalt,
D.preuni,
D.preuniadi,
D.pretot,
D.pretotadi,
D.fecent, 
D.glolin,
COALESCE (A.nomart, '') AS nomart,
COALESCE (A.nomart, '') AS nomprod, 
' ' AS checkglolin, 
0.0000 AS preunipar, 
0.0000 AS pretotpar, 
D.porcdescuento,
D.descuento, 
COALESCE (A.nomart2, '') AS nomart2,
D.porcadicional,
D.adicional,
D.codcen,
D.codana,
D.tip_impadi,
0 as nueva,
codbar,preunibruto,
saldoGral,
stockGral,
D.costo,
D.fechacosto,
costoBodega,
stockBodega,
imp_base,
imp_variable,
np,
idlinearef,
a.codfam,
a.codsub,
CASE A.selExento
WHEN 0 THEN invfamilia.exento
WHEN 1 THEN A.exentoArt
END AS exento,
	   [np]
      ,[idlinearef]
      ,[imp_base]
      ,[imp_variable]
      ,[utm]
      ,[listaprecio]
	  ,[tipoexento]
      ,[descuentoneto]
      ,[descuentoglobal]
	  ,0.000 as 'ColumnIvaLinealTotal'
	  ,0.000 as 'ColumnDescuentoLineal'
	  ,0.000 as 'ColumnDescuentoNetoExento'
	  ,0.000 as 'MontoDescuentoGlobalNetoExento'
	  ,0.000 as 'ColumnPrecioNetoLinealTotal'
	  ,0.000 as 'ColumnUnitarioNetoExento'
	  ,pos_item
	  ,A.codalt 
	  ,D.codbod
FROM            venDetalle AS D LEFT OUTER JOIN
                         invFamilia INNER JOIN
                         invArticulos AS A ON invFamilia.codfam = A.codfam ON D.codbus = A.codbus AND D.codbus = A.codbus LEFT OUTER JOIN
                         invUnidadMedida AS U ON D.coduni = U.coduni
WHERE	  D.coddoc = @coddoc
AND		  D.grudoc = @grudoc
AND 	  D.numinv = @numinv
AND       D.NUMINV <> 0
ORDER BY numlin