Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SE ASOCIAN LOS DATOS PARA CADA PAQUETE SELECCIONADO
- while @paquetes <> ''
- BEGIN
- IF CHARINDEX(',',@paquetes) > 0
- SET @paq_codigo = LEFT(@paquetes,CHARINDEX(',',@paquetes) - 1)
- ELSE
- SET @paq_codigo = @paquetes
- --Prestaciones
- INSERT INTO #informe (nombre_paq,codigo, descripcion, cantidad, ppq_valor, vpa_afecto, vpa_exento, vpa_iva, vpa_total)
- SELECT DISTINCT
- COALESCE(PC.PAQ_CODIGO, '') + ' - ' + COALESCE(PC.PAQ_DESCRIP, '') AS nombre_paq,
- CASE
- WHEN (PP.PPQ_CANTIDAD IS NULL AND PP.PPQ_VALOR IS NULL) THEN NULL
- ELSE COALESCE(PR.PRS_CODIGO, '') + ' - ' + COALESCE(PP.IAD_CODIGO, '')
- END AS codigo,
- CASE
- WHEN (PP.PPQ_CANTIDAD IS NULL AND PP.PPQ_VALOR IS NULL) THEN NULL
- ELSE (isnull(PR.PRS_DESCRIP,' ')+'-'+isnull(IA.IAD_DESCRIP, ' '))
- END AS descripcion,
- PP.PPQ_CANTIDAD AS cantidad,
- PP.PPQ_VALOR AS ppq_valor,
- VP.VPA_AFECTO AS vpa_afecto,
- VP.VPA_EXENTO AS vpa_exento,
- VP.VPA_IVA AS vpa_iva,
- VP.VPA_TOTAL AS vpa_total
- FROM PAQUETES_CONVENIO AS PC (NOLOCK)
- LEFT JOIN PRESTACION_PAQUETE AS PP (NOLOCK) ON PP.PAQ_CODIGO = PC.PAQ_CODIGO
- LEFT JOIN PRESTACION AS PR (NOLOCK)ON PR.PRS_CORREL = PP.PRS_CORREL
- LEFT JOIN ITEM_ADICIONAL AS IA (nolock) ON IA.IAD_CODIGO=PP.IAD_CODIGO
- LEFT JOIN VALOR_PAQUETE AS VP (NOLOCK) ON VP.PAQ_CODIGO = PC.PAQ_CODIGO
- WHERE PC.PAQ_CODIGO = @paq_codigo
- --Productos
- INSERT INTO #informe (nombre_paq,codigo, descripcion, cantidad, ppq_valor, vpa_afecto, vpa_exento, vpa_iva, vpa_total)
- SELECT DISTINCT
- COALESCE(PC.PAQ_CODIGO, '') + ' - ' + COALESCE(PC.PAQ_DESCRIP, '') AS nombre_paq,
- PRO.PRO_CODIGO AS codigo,
- PRO.PRO_NOMBRE AS descripcion,
- PROP.PPA_CANTIDAD AS cantidad,
- NULL AS ppq_valor,
- VP.VPA_AFECTO AS vpa_afecto,
- VP.VPA_EXENTO AS vpa_exento,
- VP.VPA_IVA AS vpa_iva,
- VP.VPA_TOTAL AS vpa_total
- FROM PAQUETES_CONVENIO AS PC(NOLOCK)
- LEFT JOIN PRODUCTO_PAQUETE AS PROP (NOLOCK) ON PROP.PAQ_CODIGO = PC.PAQ_CODIGO
- LEFT JOIN PRODUCTO AS PRO (NOLOCK)ON PRO.PRO_CORREL = PROP.PRO_CORREL
- LEFT JOIN VALOR_PAQUETE AS VP (NOLOCK) ON VP.PAQ_CODIGO = PC.PAQ_CODIGO
- WHERE PC.PAQ_CODIGO = @paq_codigo
- --cont. cicl.
- IF CHARINDEX(',',@paquetes) = 0
- SET @paquetes = ''
- ELSE
- SET @paquetes = RIGHT(@paquetes,LEN(@paquetes) - CHARINDEX(',',@paquetes))
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement