

if exists (select * from sys.objects where object_id = OBJECT_ID(N'[dbo].[for_itemDocumentoXTraslado]') and type in (N'P', N'PC'))
drop procedure  [dbo].[for_itemDocumentoXTraslado]
go

CREATE PROCEDURE [dbo].[for_itemDocumentoXTraslado]
	@p_id INT,
	@p_eid varchar(100)
AS
BEGIN
SELECT      row_number()over(order by doc_itemDocumento.id_itemDocumento_superior asc,doc_itemDocumento.id_catalogo asc) as num,
			doc_itemDocumento.id, doc_itemDocumento.id_itemDocumento_superior, doc_itemDocumento.itemDocumento, doc_itemDocumento.id_catalogo, 
            doc_itemDocumento.cantidadPlaneado as cantidadEjecutado, doc_itemDocumento.valorUnitarioPlaneado as valorUnitarioEjecutado, doc_itemDocumento.subtotalPlaneado as subtotalEjecutado, 
            doc_itemDocumento.totalPlaneado as totalEjecutado, doc_itemDocumento.dtoPlaneado as dtoEjecutado, doc_itemDocumento.ivaPlaneado as ivaEjecutado,
			cat_catalogo.catalogo,cat_catalogo.codigoInventario as catalogo_codigo
FROM        doc_itemDocumento INNER JOIN
            doc_documento ON doc_documento.id = doc_itemDocumento.id_documento INNER JOIN
            doc_itemDocumento AS doc_itemDocumento_superior ON doc_itemDocumento_superior.id = doc_itemDocumento.id_itemDocumento_superior inner join
			cat_catalogo on cat_catalogo.id=doc_itemDocumento.id_catalogo
			
	WHERE 	(doc_itemDocumento.id_documento = @p_id
			and doc_itemDocumento.eid like '01' +'%')
                        and doc_itemdocumento.active = 1
	order by doc_itemDocumento.id_itemDocumento_superior asc,doc_itemDocumento.id_catalogo asc
END


