Monday, June 29, 2009

Addition

* This function will add to values together. If one or both of the values is null, it will replace the null with a 0 */

CREATE FUNCTION dbo.FuncAddition (@String1 as decimal(10,2), @String2 as decimal(10,2)) RETURNS decimal(10,2)
AS
BEGIN

declare @Result as decimal(10,2)
if @String1 is null set @String1 = 0
if @String2 is null set @String2 = 0

set @Result = @String1 + @String2

Return @Result
End

eg:
dbo.FuncAddition(50,50) =100
dbo.FuncAddition (10,Null) = 10

No comments:

Post a Comment