Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [LL_GPPS_2017]
- GO
- /****** Object: StoredProcedure [dbo].[uspUpdateExchangeRates] Script Date: 17/8/2017 10:01:36 AM ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- =============================================
- -- Author: Vitu Mhone <mhone.vitu@gmail.com>
- -- Create date: 16 August 2017 10:27 am
- -- Description: Stored procedure to update
- -- exchange rates by fetching
- -- them from TSS and updating
- -- the SALE_EXCHANGE_RATE column
- -- =============================================
- ALTER PROCEDURE [dbo].[uspUpdateExchangeRates]
- AS
- BEGIN
- -- SET NOCOUNT ON added to prevent extra result sets from
- -- interfering with SELECT statements.
- SET NOCOUNT ON;
- DECLARE @TransactionNumber int
- DECLARE @FloorCode varchar(10)
- DECLARE @SaleDate date
- DECLARE MyCursor CURSOR FOR
- SELECT TRANSACTION_NUMBER, FLOOR_CODE, SALE_DATE FROM tbl_Grower_Proceeds WHERE PR_TYPE IN('C','S')
- BEGIN
- OPEN MyCursor
- FETCH NEXT FROM MyCursor INTO
- @TransactionNumber, @FloorCode, @SaleDate
- WHILE @@FETCH_STATUS = 0
- BEGIN
- DECLARE @ExchangeRate decimal(8,4)
- -- get the exchange rate from TSS for the sale date in question
- SELECT @ExchangeRate = dbo.udfGetExchangeRate(@SaleDate)
- IF (@ExchangeRate IS NULL)
- BEGIN
- SET @ExchangeRate = 0
- END
- -- update the exchange rate in GPPS for the sale date
- UPDATE tbl_Grower_Proceeds
- SET SALE_EXCHANGE_RATE = @ExchangeRate
- WHERE TRANSACTION_NUMBER = @TransactionNumber
- AND FLOOR_CODE = @FloorCode
- FETCH NEXT FROM MyCursor
- INTO @TransactionNumber, @FloorCode, @SaleDate
- END
- CLOSE MyCursor
- DEALLOCATE MyCursor
- END
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement