CREATE PROCEDURE [dbo].[SP_SV_Exception_Report]
(
@Inv_Type_Code varchar(5),
@Inv_Number numeric
)
AS
BEGIN
DECLARE @Inv_Type_ID VARCHAR(5)
SET @Inv_Type_ID = (SELECT Inv_Type_ID FROM INVOICE_TYPE WHERE Inv_Type_Code= @Inv_Type_Code )
IF(@Inv_Type_Code = 'AWI')
BEGIN
Select
INV_TYPE_DESC,
INV.INV_NUMBER ,
INV_TAX_POINT_DATE,
Meter_Point_Reference_Number as TheValue, @Inv_Type_Code as InvTypeCode,
GENERALEXCEPTION from METERING_JOB_DETAILS MJD INNER JOIN INVOICE INV
ON MJD.INV_NUMBER = INV.INV_NUMBER
INNER JOIN INVOICE_TYPE ITP ON ITP.INV_TYPE_ID = INV.INV_TYPE_ID
WHERE
INV.INV_TYPE_ID = @Inv_Type_ID
AND MJD.INV_NUMBER = @Inv_Number
AND GENERALEXCEPTION IS NOT NULL
ORDER BY INV_TAX_POINT_DATE
END
ELSE IF @Inv_Type_Code IN( 'MAV','MFV','MRV')
BEGIN
Select
INV_TYPE_DESC,
INV.INV_NUMBER ,
INV_TAX_POINT_DATE,
MPO_REFERENCE AS TheValue, @Inv_Type_Code as InvTypeCode,
GENERALEXCEPTION from METERING_BACKING_ADJUSTMENT_CHARGE_ITEM MBACI
INNER JOIN METERING_BACKING_ADJUSTMENT MBA
ON MBA.METERING_BACKING_ADJUSTMENT_ID = MBACI.METERING_BACKING_ADJUSTMENT_ID
INNER JOIN INVOICE INV
ON MBA.AREA_INVOICE_NUMBER = INV.INV_NUMBER
INNER JOIN INVOICE_TYPE ITP ON ITP.INV_TYPE_ID = INV.INV_TYPE_ID
WHERE
INV.INV_TYPE_ID = @Inv_Type_ID
AND MBA.AREA_INVOICE_NUMBER = @Inv_Number
AND GENERALEXCEPTION IS NOT NULL
ORDER BY INV_TAX_POINT_DATE
END
ELSE IF @Inv_Type_Code IN ('MFR', 'MLV')
BEGIN
Select
INV_TYPE_DESC,
INV.INV_NUMBER ,
INV_TAX_POINT_DATE,
MPO_REFERENCE AS TheValue, @Inv_Type_Code as InvTypeCode,
GENERAL_EXCEPTION from METERING_BACKING_STANDARD_CHARGE MBSC INNER JOIN METERING_BACKING_STANDARD_CHARGE_ITEM MBSCI
ON MBSC.METERING_BACKING_STANDARD_CHARGE_ID = MBSCI.METERING_BACKING_STANDARD_CHARGE_ID
INNER JOIN INVOICE INV ON INV.INV_NUMBER = MBSC.AREA_INVOICE_NUMBER
INNER JOIN INVOICE_TYPE ITP ON ITP.INV_TYPE_ID = INV.INV_TYPE_ID
WHERE
INV.INV_TYPE_ID = @Inv_Type_ID
AND MBSC.AREA_INVOICE_NUMBER = @Inv_Number
AND GENERAL_EXCEPTION IS NOT NULL
ORDER BY INV_TAX_POINT_DATE
END
ELSE IF(@Inv_Type_Code = 'MRP')
BEGIN
Select
INV_TYPE_DESC,
INV.INV_NUMBER,
INV_TAX_POINT_DATE,
MPO_REFERENCE AS TheValue, @Inv_Type_Code as InvTypeCode,
GENERALEXCEPTION from METERING_NPD_DATA MND INNER JOIN INVOICE INV
ON MND.AREA_INVOICE_NUMBER = INV.INV_NUMBER
INNER JOIN INVOICE_TYPE ITP ON ITP.INV_TYPE_ID = INV.INV_TYPE_ID
WHERE
INV.INV_TYPE_ID = @Inv_Type_ID
AND MND.AREA_INVOICE_NUMBER = @Inv_Number
AND GENERALEXCEPTION IS NOT NULL
ORDER BY INV_TAX_POINT_DATE
END
END
|