Advertisement
Guest User

Exchange Rate Stored Procedure

a guest
Aug 17th, 2017
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.70 KB | None | 0 0
  1. USE [LL_GPPS_2017]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[uspUpdateExchangeRates]    Script Date: 17/8/2017 10:01:36 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:      Vitu Mhone <mhone.vitu@gmail.com>
  10. -- Create date: 16 August 2017 10:27 am
  11. -- Description: Stored procedure to update
  12. --              exchange rates by fetching
  13. --              them from TSS and updating
  14. --              the SALE_EXCHANGE_RATE column
  15. -- =============================================
  16. ALTER PROCEDURE [dbo].[uspUpdateExchangeRates]
  17.    
  18. AS
  19. BEGIN
  20.     -- SET NOCOUNT ON added to prevent extra result sets from
  21.     -- interfering with SELECT statements.
  22.     SET NOCOUNT ON;
  23.  
  24.     DECLARE @TransactionNumber int
  25.     DECLARE @FloorCode varchar(10)
  26.     DECLARE @SaleDate date
  27.     DECLARE MyCursor CURSOR FOR
  28.  
  29.     SELECT TRANSACTION_NUMBER, FLOOR_CODE, SALE_DATE FROM tbl_Grower_Proceeds WHERE PR_TYPE IN('C','S')
  30.  
  31.     BEGIN
  32.         OPEN MyCursor
  33.             FETCH NEXT FROM MyCursor INTO
  34.                 @TransactionNumber, @FloorCode, @SaleDate
  35.             WHILE @@FETCH_STATUS = 0
  36.                 BEGIN              
  37.                     DECLARE @ExchangeRate decimal(8,4)
  38.  
  39.                     -- get the exchange rate from TSS for the sale date in question
  40.                     SELECT @ExchangeRate = dbo.udfGetExchangeRate(@SaleDate)
  41.  
  42.                     IF (@ExchangeRate IS NULL)
  43.                         BEGIN
  44.                             SET @ExchangeRate = 0
  45.                         END
  46.  
  47.                     -- update the exchange rate in GPPS for the sale date
  48.                     UPDATE tbl_Grower_Proceeds
  49.                     SET SALE_EXCHANGE_RATE   = @ExchangeRate
  50.                     WHERE TRANSACTION_NUMBER = @TransactionNumber
  51.                     AND FLOOR_CODE           = @FloorCode
  52.  
  53.                     FETCH NEXT FROM MyCursor
  54.                     INTO @TransactionNumber, @FloorCode, @SaleDate
  55.                 END
  56.             CLOSE MyCursor
  57.             DEALLOCATE MyCursor
  58.         END
  59.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement