Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1.  @ZBACK is the number of times the routine will run

2.  @ZIDNO and   @ZLOANUMBER   is the particular record which is      

    selected from the 2 linked tables a. LOANS and b. INTEREST


Request
______


Can you please provide a better way to perform the undernoted routine

SQL
ALTER Procedure [dbo].[sp_Construction]
(
		@ZIDNO           VarChar(50),
                @ZAPPRS_NO       VarChar(50),
                @ZLOANUMBER      VarChar(50),
                @ZBACK           SMALLINT        , 
                @RETURN          VARCHAR(4)OUTPUT
 )
 
 

	SET @ZCCNT =1
	
	
	WHILE @ZCCNT <= @ZBACK 
				
	BEGIN


	CREATE TABLE #VOANS
	(
	AIDNO       varchar(20),
	ACOMPCOUNT  smallint ,
	BINT_NO     varchar(20),
	BINT_NAME   varchar(50),
	BRATES      numeric(18,4)
)



	INSERT INTO #VOANS
	SELECT A.IDNO     AS AIDNO         ,
	A.COMPCOUNT     AS  ACOMPCOUNT  ,
	B.INT_NO        AS  BINT_NO     ,
	B.INT_NAME      AS  BINT_NAME   ,
	B.RATES         AS  BRATES
	FROM LOANS A JOIN INTEREST B
	ON A.INT_NO = B.INT_NO WHERE  B.INT_NO=@ZINT_NAME AND A.IDNO =@ZIDNO AND A.LOANUMBER= @ZLOANUMBER


	DECLARE NNLOANS CURSOR FOR SELECT  AIDNO  ,
				    ACOMPCOUNT  ,
				   BINT_NO     ,
				   BINT_NAME   ,
				   BRATES FROM #VOANS

	        
	OPEN NNLOANS

	FETCH NEXT FROM NNLOANS  INTO    @AIDNO     ,
				   @ACOMPCOUNT   ,
				   @BINT_NO     ,
				   @BINT_NAME  ,
				   @BRATES         
				
									   
	WHILE @@FETCH_STATUS = 0
	BEGIN	

			 UPDATE LOANS  SET 
					OUTSTAND  =       @AADVLOAN-@MMPRINC, 
					TOTPAYMT  =       @MMDEDUCT 
					 WHERE IDNO =@AIDNO AND LOANUMBER=@ALOANUMBER
		
	
	END
	
		
	SET @ZCCNT =@ZCCNT+1
			
	END
	
				
	CLOSE NNLOANS
		
	DEALLOCATE NNLOANS
Posted
Updated 1-Jun-15 23:08pm
v2
Comments
Andy Lanng 2-Jun-15 5:06am    
Homework?
Member 10744248 2-Jun-15 5:16am    
No please

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
Member 10744248 2-Jun-15 5:18am    
please this is not home work .

Its a bigger program which I have, and I am not getting the output right
Member 10744248 2-Jun-15 5:19am    
I have reduced it to this form so as to get a better way to run this routine
Member 10744248 2-Jun-15 5:21am    
1. I am using a crude way to do the routine, and I want a better way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900