Posts Using COALESCE
Post
Cancel

Using COALESCE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Note: COALESCE returns the first nonnull expression among its arguments.

ALTER  PROCEDURE [dbo].[MDR_UpdateCurrencyDiscountIndex]
	@Currency varchar(3), 
	@DomesticDiscountIdx varchar(50)= NULL,
	@FXDiscountIdx varchar(50) = NULL
AS

BEGIN
	BEGIN TRANSACTION
	UPDATE CurrenciesMaster
	SET
		DomesticDiscountIdx = COALESCE(@DomesticDiscountIdx, DomesticDiscountIdx),
		FXDiscountIdx = COALESCE(@FXDiscountIdx, FXDiscountIdx)
	WHERE Currency = @Currency	
	if @@ERROR <> 0 
	BEGIN
		ROLLBACK TRANSACTION
		RETURN @@ERROR
	END
	COMMIT TRANSACTION
	RETURN 0
END
This post is licensed under CC BY 4.0 by the author.