jacktheripper
jacktheripper

Reputation: 19

Creating a SQL-Server function which turns negative numbers into null

In SQL-Server am trying to create a function which turns negative values (int) into nulls/zero's. However the ways it is now all the numbers (also the positive ones) get turned into zero.

create FUNCTION planning.FN_test_return_zero_incaseof_negative_value (@value as int)

RETURNS int

BEGIN
    if @value < 0 return 0
    DECLARE @days as int


RETURN @days
END
GO

Upvotes: -2

Views: 112

Answers (1)

Cetin Basoz
Cetin Basoz

Reputation: 23797

create FUNCTION planning.FN_test_return_zero_incaseof_negative_value (@value as int)

RETURNS int

BEGIN
    if @value < 0 
       return 0
    return @value
END
GO

Upvotes: 1

Related Questions