Member 12183079 Ответов: 2

Как быстро получить быстрые данные в SQL server


--Exec [DisplayFeeBillDescription] null,null,null,null,null,1,25,null,true,null
 
    
ALTER PROCEDURE [dbo].[DisplayFeeBillDescription]                   
 @InstallmentID INTEGER=NULL,                                
 @CategoryID INTEGER=NULL,                                
 @ShiftID INTEGER=NULL,                            
 @CourseID INTEGER=NULL,                            
 @SpecializationID INTEGER=NULL,                                
 @InstituteID INTEGER=NULL,                          
 @SessionID INTEGER=NULL,              
 @ActiveID BIT=NULL,
 @IsRegistered BIT,
 @ProgramID int=null                                    
AS                                
 SET NOCOUNT ON                           
 -- BilledAmount = Opening Trimester Balance                   
 DECLARE @result TABLE                    
 (                    
  ShiftID INT,                    
  CourseID INT,                    
  SpecializationID INT,                    
  Batch NVARCHAR(MAX),         
  SessionID INT,                      
  StudentID INT,                    
  AdmissionNumber NVARCHAR(MAX),                    
  StudentName NVARCHAR(MAX),             
  BilledAmount NUMERIC(18,2) ,             
  TrimesterBilledAmount NUMERIC(18,2),             
  PaidAmount NUMERIC(18,2) ,             
  Concession NUMERIC(18,2) ,                               
  OutstandingAmount NUMERIC(18,2),
  AdjustedAmount NUMERIC(18,2),
  PaymentAmount NUMERIC(18,2),
  TrimesterStudentID INT                   
 )                     
  DECLARE @misc TABLE                    
 (                    
  ShiftID INT,                    
  CourseID INT,                    
  SpecializationID INT,                    
  Batch NVARCHAR(MAX),                       
  SessionID INT,        
  StudentID INT,                    
  AdmissionNumber NVARCHAR(MAX),                    
  StudentName NVARCHAR(MAX),            
  BilledAmount NUMERIC(18,2) ,             
  TrimesterBilledAmount NUMERIC(18,2),             
  PaidAmount NUMERIC(18,2) ,             
  Concession NUMERIC(18,2) ,                                 
  OutstandingAmount NUMERIC(18,2),
  AdjustedAmount NUMERIC(18,2),
  PaymentAmount NUMERIC(18,2)                   
 )                      
                        
    --------------------------Student Details-----------------------------------------                  
                      
   Insert Into @result(ShiftID,CourseID,SpecializationID,Batch,SessionID,StudentID,AdmissionNumber,StudentName, 
   BilledAmount, PaidAmount ,Concession , OutstandingAmount, AdjustedAmount ,PaymentAmount ,TrimesterBilledAmount,TrimesterStudentID)                      
   SELECT DISTINCT SP.ShiftID,SP.CourseID,NULL,SH.Shift +'/'+CO.Course AS Batch,SP.SessionID,                       
   SP.StudentID,SP.AdmissionNumber,dbo.GetFullName(SP.FirstName,SP.MiddleName,SP.LastName)[StudentName],
   0 [BilledAmount],0 [PaidAmount] ,0 [Concession],0 [OutstandingAmount],0 [AdjustedAmount] ,0 [PaymentAmount],0 [TrimesterBilledAmount],TR.StudentID                                 
   FROM biz_StudentProfile SP(NOLOCK)                      
    INNER JOIN biz_Shift SH(NOLOCK) ON SP.ShiftID=SH.ShiftID                                    
    INNER JOIN biz_Course CO(NOLOCK) ON SP.CourseID=CO.CourseID  
    inner join biz_programcourse PG(NoLock) on PG.courseID=Co.courseid                                  
    --LEFT JOIN biz_Specialization SS(NOLOCK) ON SP.StreamID=SS.SpecializationID 
    LEFT JOIN biz_TrimesterRegistration TR(NOLOCK) ON TR.SessionID=SP.SessionID AND TR.StudentID=SP.StudentID
   WHERE (@CategoryID IS NULL OR SP.CategoryID=@CategoryID) AND                                
    (@ShiftID IS NULL OR SP.ShiftID=@ShiftID)  AND                                  
    (@CourseID IS NULL OR SP.CourseID=@CourseID)  AND                                  
    (@SpecializationID IS NULL OR SP.StreamID=@SpecializationID)  AND                             
    (@InstituteID IS NULL OR SP.InstituteID=@InstituteID) AND                            
    (@SessionID IS NULL OR SP.SessionID=@SessionID) AND                              
    (@ActiveID IS NULL OR SP.IsActive=@ActiveID) AND   
    (@IsRegistered=0 OR TR.StudentID IS NOT NULL)  and  
    (@ProgramID is Null OR pg.programID=@ProgramID)          
   order by AdmissionNumber                          
                        
                      
    ------------*************************************************************----------                     
    --------------------------Fee Bill ------------------------------------------------                        
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount, PaidAmount ,Concession, OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.BilledAmount + SUM(ISNULL(FB.Amount,0))[BilledAmount], 
    R.PaidAmount ,R.Concession, R.OutstandingAmount + SUM(ISNULL(FB.Amount,0)) [OutstandingAmount]            
    FROM biz_FeeBill FB(NOLOCK)                        
    INNER JOIN biz_Installment IL(NOLOCK) ON FB.InstallmentID=IL.InstallmentID                   
    JOIN @result R  ON R.StudentID=FB.StudentID                     
    WHERE  (@SessionID IS NULL OR FB.SessionID <= @SessionID)                  
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaidAmount ,R.Concession,R.OutstandingAmount                  
                  
                         
                       
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaidAmount=M.PaidAmount,            
     Concession=M.Concession                
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------                       
           
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,TrimesterBilledAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    ISNULL(R.TrimesterBilledAmount,0) + SUM(ISNULL(FB.Amount,0))[TrimesterBilledAmount]              
    FROM biz_FeeBill FB(NOLOCK)                        
    INNER JOIN biz_Installment IL(NOLOCK) ON FB.InstallmentID=IL.InstallmentID                   
    JOIN @result R  ON R.StudentID=FB.StudentID AND FB.SessionID=R.SessionID        
    WHERE (@SessionID IS NULL OR FB.SessionID=@SessionID)      
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.TrimesterBilledAmount                  
                  
    UPDATE @result SET TrimesterBilledAmount=M.TrimesterBilledAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount, PaidAmount ,Concession,OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount - SUM(ISNULL(FB.Amount,0)) [BilledAmount], R.PaidAmount [PaidAmount] ,R.Concession,          
    R.OutstandingAmount - SUM(ISNULL(FB.Amount,0)) [OutstandingAmount]                   
    FROM biz_FeeBill FB(NOLOCK)                        
    INNER JOIN biz_Installment IL(NOLOCK) ON FB.InstallmentID=IL.InstallmentID  AND ISNULL(FB.IsCancel,0)=1                        
    JOIN @result R  ON R.StudentID=FB.StudentID                     
    WHERE  (@SessionID IS NULL OR FB.SessionID <= @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaidAmount ,R.Concession,R.OutstandingAmount                   
            
            
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaidAmount=M.PaidAmount,            
     Concession=M.Concession                    
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   --------------------****************************************------------------------  
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,TrimesterBilledAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    ISNULL(R.TrimesterBilledAmount,0) - SUM(ISNULL(FB.Amount,0))[TrimesterBilledAmount]              
    FROM biz_FeeBill FB(NOLOCK)                        
    INNER JOIN biz_Installment IL(NOLOCK) ON FB.InstallmentID=IL.InstallmentID  AND ISNULL(FB.IsCancel,0)=1                 
    JOIN @result R  ON R.StudentID=FB.StudentID AND FB.SessionID=R.SessionID        
    WHERE (@SessionID IS NULL OR FB.SessionID=@SessionID)      
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.TrimesterBilledAmount                  
                  
    UPDATE @result SET TrimesterBilledAmount=M.TrimesterBilledAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------                    
   ----------------------------Fee Receipt --------------------------------------------                     
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount,PaidAmount ,Concession,OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount - SUM(ISNULL(RD.DepositedAmount,0)) [BilledAmount], R.PaidAmount [PaidAmount],R.Concession,           
    R.OutstandingAmount - SUM(ISNULL(RD.DepositedAmount,0)) [OutstandingAmount]               
    FROM biz_FeeReceipt FR(NOLOCK)                        
    INNER JOIN biz_FeeReceiptDetails RD (NOLOCK) ON FR.FeeReceiptID=RD.FeeReceiptID                        
    LEFT JOIN biz_FeeBill FB (NOLOCK) ON FB.FeeBillID=RD.FeeBillID                      
    JOIN @result R  ON R.StudentID=FR.StudentID                    
    WHERE  (@SessionID IS NULL OR FR.SessionID <= @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaidAmount ,R.Concession,R.OutstandingAmount                  
              
                        
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaidAmount=M.PaidAmount,            
     Concession=M.Concession                  
    FROM @result R                        
    JOIN @misc M ON R.StudentID = M.StudentID                    
  ------------------------*****************************************----------------------    
  
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,PaidAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.PaidAmount + SUM(ISNULL(RD.DepositedAmount,0)) [PaidAmount]        
    FROM biz_FeeReceipt FR(NOLOCK)                        
    INNER JOIN biz_FeeReceiptDetails RD (NOLOCK) ON FR.FeeReceiptID=RD.FeeReceiptID                        
    LEFT JOIN biz_FeeBill FB (NOLOCK) ON FB.FeeBillID=RD.FeeBillID                      
    JOIN @result R  ON R.StudentID=FR.StudentID                    
    WHERE  (@SessionID IS NULL OR FR.SessionID = @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName, R.PaidAmount     
                     
                  
    UPDATE @result SET PaidAmount=M.PaidAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------                         
   ---------------------------------Cancel Fee Receipt----------------------------------                        
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount,PaidAmount ,Concession,OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount + SUM(ISNULL(RD.DepositedAmount,0))[BilledAmount], R.PaidAmount ,R.Concession,          
    R.OutstandingAmount + SUM(ISNULL(RD.DepositedAmount,0)) [OutstandingAmount]          
    FROM biz_FeeReceipt FR(NOLOCK)                        
    INNER JOIN biz_FeeReceiptDetails RD (NOLOCK) ON FR.FeeReceiptID=RD.FeeReceiptID  AND ISNULL(FR.IsCancel,0)=1                      
    LEFT JOIN biz_FeeBill FB (NOLOCK) ON FB.FeeBillID=RD.FeeBillID                        
    JOIN @result R  ON R.StudentID=FR.StudentID                    
    WHERE  (@SessionID IS NULL OR FR.SessionID <= @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaidAmount ,R.Concession,R.OutstandingAmount                
                         
                         
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaidAmount=M.PaidAmount,            
     Concession=M.Concession                   
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                      
    ---------------------****************************************-----------------------             
    
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,PaidAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.PaidAmount - SUM(ISNULL(RD.DepositedAmount,0)) [PaidAmount]        
    FROM biz_FeeReceipt FR(NOLOCK)                        
    INNER JOIN biz_FeeReceiptDetails RD (NOLOCK) ON FR.FeeReceiptID=RD.FeeReceiptID  AND ISNULL(FR.IsCancel,0)=1                        
    LEFT JOIN biz_FeeBill FB (NOLOCK) ON FB.FeeBillID=RD.FeeBillID                      
    JOIN @result R  ON R.StudentID=FR.StudentID                    
    WHERE  (@SessionID IS NULL OR FR.SessionID = @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName, R.PaidAmount     
                     
                  
    UPDATE @result SET PaidAmount=M.PaidAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------                 
   ------------------------- Fee Refund ----------------------------------------------                     
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount, AdjustedAmount ,Concession, OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount - SUM(ISNULL(FR.Amount,0)) [BilledAmount], R.AdjustedAmount [AdjustedAmount] ,R.Concession,          
    R.OutstandingAmount - SUM(ISNULL(FR.Amount,0)) [OutstandingAmount]                   
    FROM biz_FeeRefund FR                     
    JOIN @result R  ON R.StudentID=FR.StudentID                     
    WHERE (@SessionID IS NULL OR FR.SessionID <= @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.AdjustedAmount ,R.Concession,R.OutstandingAmount                        
                        
                         
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     AdjustedAmount=M.AdjustedAmount,            
     Concession=M.Concession                      
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                        
    -----*************************************************************************------   
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,AdjustedAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.AdjustedAmount + SUM(ISNULL(FR.Amount,0))[AdjustedAmount]                  
    FROM biz_FeeRefund FR                     
    JOIN @result R  ON R.StudentID=FR.StudentID                     
    WHERE (@SessionID IS NULL OR FR.SessionID = @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.AdjustedAmount
                     
                  
    UPDATE @result SET AdjustedAmount=M.AdjustedAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------   
                    
     ------------------------- Cancel Fee Refund  --------------------------------------                     
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount,AdjustedAmount ,Concession,OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount + SUM(ISNULL(FR.Amount,0)) [BilledAmount], R.AdjustedAmount [AdjustedAmount] ,R.Concession,          
    R.OutstandingAmount + SUM(ISNULL(FR.Amount,0)) [OutstandingAmount]             
    FROM biz_FeeRefund FR                     
    JOIN @result R  ON R.StudentID=FR.StudentID AND ISNULL(FR.IsCancel,0)=1                    
    WHERE  (@SessionID IS NULL OR FR.SessionID <= @SessionID)                     
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.AdjustedAmount ,R.Concession,R.OutstandingAmount                         
                        
                     
                         
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     AdjustedAmount=M.AdjustedAmount,            
     Concession=M.Concession                    
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                        
    -----*************************************************************************------                    
  
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,AdjustedAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.AdjustedAmount - SUM(ISNULL(FR.Amount,0))[AdjustedAmount]                  
    FROM biz_FeeRefund FR                     
    JOIN @result R  ON R.StudentID=FR.StudentID  AND ISNULL(FR.IsCancel,0)=1                    
    WHERE (@SessionID IS NULL OR FR.SessionID = @SessionID)                    
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.AdjustedAmount
                     
                  
    UPDATE @result SET AdjustedAmount=M.AdjustedAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------   
                      
                        
     ------------------------- Refund Payment  -----------------------------------------                     
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount,PaymentAmount ,Concession,OutstandingAmount)                    
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount + SUM(ISNULL(PD.PaymentAmount,0)) [BilledAmount], R.PaymentAmount  [PaymentAmount] ,R.Concession,          
    R.OutstandingAmount + SUM(ISNULL(PD.PaymentAmount,0)) [OutstandingAmount]                  
    FROM biz_FeePayment FP(NOLOCK)                         
    INNER JOIN biz_FeePaymentDetails PD (NOLOCK) ON FP.FeePaymentID=PD.FeePaymentID                    
    INNER JOIN @result R  ON R.StudentID=FP.StudentID                     
    WHERE  (@SessionID IS NULL OR FP.SessionID<=@SessionID)                        
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaymentAmount ,R.Concession,R.OutstandingAmount                        
                      
                     
                        
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaymentAmount=M.PaymentAmount,            
     Concession=M.Concession                     
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                        
    -----*************************************************************************------            
          
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,PaymentAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.PaymentAmount + SUM(ISNULL(PD.PaymentAmount,0))  [PaymentAmount]                
    FROM biz_FeePayment FP(NOLOCK)                         
    INNER JOIN biz_FeePaymentDetails PD (NOLOCK) ON FP.FeePaymentID=PD.FeePaymentID                    
    INNER JOIN @result R  ON R.StudentID=FP.StudentID                     
    WHERE  (@SessionID IS NULL OR FP.SessionID=@SessionID)                        
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.PaymentAmount
                     
                  
    UPDATE @result SET PaymentAmount=M.PaymentAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
   -----------------------******************************--------------------------------                  
                        
     ------------------------- Cancel Refund Payment  ----------------------------------                     
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,
    BilledAmount, PaymentAmount ,Concession,OutstandingAmount)         
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount - SUM(ISNULL(PD.PaymentAmount,0)) [BilledAmount], R.PaymentAmount[PaymentAmount] ,R.Concession,          
    R.OutstandingAmount - SUM(ISNULL(PD.PaymentAmount,0)) [OutstandingAmount]                   
    FROM biz_FeePayment FP(NOLOCK)                         
    INNER JOIN biz_FeePaymentDetails PD (NOLOCK) ON ISNULL(FP.IsCancel,0)=1 AND FP.FeePaymentID=PD.FeePaymentID                    
    INNER JOIN @result R  ON R.StudentID=FP.StudentID              
    WHERE   (@SessionID IS NULL OR FP.SessionID<=@SessionID)               
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.BilledAmount, R.PaymentAmount ,R.Concession,R.OutstandingAmount 
                      
                        
    UPDATE @result SET OutstandingAmount=M.OutstandingAmount,            
     BilledAmount=M.BilledAmount,            
     PaymentAmount=M.PaymentAmount,            
     Concession=M.Concession                    
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                        
    -----*************************************************************************------      
    
            
    DELETE FROM @misc                    
                        
    INSERT INTO @misc (ShiftID,CourseID,SpecializationID,Batch,StudentID,AdmissionNumber,StudentName,PaymentAmount)  
    SELECT R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,
    R.PaymentAmount - SUM(ISNULL(PD.PaymentAmount,0))  [PaymentAmount]                
    FROM biz_FeePayment FP(NOLOCK)                         
    INNER JOIN biz_FeePaymentDetails PD (NOLOCK) ON FP.FeePaymentID=PD.FeePaymentID  AND ISNULL(FP.IsCancel,0)=1                  
    INNER JOIN @result R  ON R.StudentID=FP.StudentID                     
    WHERE  (@SessionID IS NULL OR FP.SessionID=@SessionID)                        
    GROUP BY R.ShiftID,R.CourseID,R.SpecializationID,R.Batch,R.StudentID,R.AdmissionNumber,R.StudentName,R.PaymentAmount
                     
                  
    UPDATE @result SET PaymentAmount=M.PaymentAmount        
    FROM @result R                    
    JOIN @misc M ON R.StudentID = M.StudentID                    
                            
                        
                               
 SELECT * FROM @result 
   
   
   
                     
 SET NOCOUNT OFF


Что я уже пробовал:

выше я пишу запрос и получаю только запись 1011 но это занимает 1.51 мин и выбрасывает исключение

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.


так как же решить пожалуйста помогите

2 Ответов

Рейтинг:
15

Jörgen Andersson

Начните с копирования содержимого процедуры в SSMS.
Удалите инструкцию alter procedure и закомментируйте все остальное.
Затем установите все параметры вручную в тестовые значения.
Затем вы удаляете комментарии для первого оператора и запускаете его.
Если он работает нормально, вы комментируете первый оператор и раскомментируете второй оператор. И снова бежать.

Продолжайте делать это до тех пор, пока не обнаружите, какие утверждения вызывают у вас проблемы.
Попробуйте проанализировать, почему это утверждение медленное, и в конце концов вы можете спросить нас снова.


Maciej Los

Хороший совет!

Рейтинг:
1

Maciej Los

Во-первых, никто не может определить причину вышеуказанной ошибки в таком длинном запросе.

Пожалуйста, прочтите это: c# - тайм-аут истек. Время ожидания истекло до завершения операции или сервер не отвечает. Оператор был прерван - переполнение стека[^]
Там вы найдете подробную информацию о причинах ошибки "исключение тайм-аута".