Question : How  to use the Switch case in the Report Expression effectively

Hi Experts,


Explanation of the Logic : I have used 4 tables and only two columns  
                                           1. Meter_Point_Reference_Number
                                           2. MPO_REFERENCE
Since , i have to use the same  column names  and bind to  the report dataset , i have used the alias names for these columns and used a switch case in the report exp[ression. The stored procedure is 100% working fine , but there is a problem with the switch case. I get an error message like this(#error) in the report expression and i don't know the message and i cannot  even debug either . please find  the switch case and the Stored procedure logic here under , correct my switch case or if i have to write a custom code , please help me with the code as I am poor at writing custom code. Ultimately , please provide me the solution.      

Switch  Case used in the  Report Expression :
                 =Switch(
        Parameters!Inv_Type_Code.Value = "AWI",
                   Fields!MPRN_AWI.Value,
        Parameters!Inv_Type_Code.Value = "MAV",
                   Fields!MPRN_MAV.Value,
         Parameters!Inv_Type_Code.Value = "MFV",
                   Fields!MPRN_MFV.Value,
        Parameters!Inv_Type_Code.Value  = "MRV",  
                   Fields!MPRN_MRV.Value,
        Parameters!Inv_Type_Code.Value = "MRP",
                   Fields!MPRN_MRP.Value,
        Parameters!Inv_Type_Code.Value = "MFR",
                   Fields!MPRN_MFR.Value,
       Parameters!Inv_Type_Code.Value = "MLV",
                   Fields!MPRN_MLV.Value
        )                

Stored Procedure Logic :
IF(@Inv_Type_Code  = 'AWI') then
BEGIN
            Select
      Meter_Point_Reference_Number as MPRN_AWI  from METERING_JOB_DETAILS    
                                                                                WHERE INV_NUMBER = @INV_nUMBER          
  END

ELSE IF @Inv_Type_Code  IN(  'MAV','MFV','MRV')
BEGIN
        Select
                   MPO_REFERENCE AS MPRN_MAV,
                   MPO_REFERENCE AS MPRN_MFV,
                   MPO_REFERENCE AS MPRN_MRV        
                                 from METERING_BACKING_ADJUSTMENT_CHARGE_ITEM
                     WHERE   INV_NUMBER = @INV_nUMBER
END

ELSE IF @Inv_Type_Code IN ('MFR', 'MLV')
BEGIN
         Select
                       MPO_REFERENCE AS MPRN_MFR,
        MPO_REFERENCE AS MPRN_MLV
                        from  METERING_BACKING_STANDARD_CHARGE
                                                    WHERE   INV_NUMBER = @INV_nUMBER
END

ELSE IF(@Inv_Type_Code  = 'MRP')
BEGIN
         Select
                 MPO_REFERENCE AS MPRN_MRP         from METERING_NPD_DATA  
                                           WHERE   INV_NUMBER = @INV_nUMBER
END


Regards,

Sreekanth.

Answer : How  to use the Switch case in the Report Expression effectively

Hello Sreekanth,

Same issue as with your previous version: the stored proc is not always returning the same (number of) fields...

See attached snippet for an attempt to get it right.  I'm applying the same logic as I did previously.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
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
Random Solutions  
 
programming4us programming4us