add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE FUNCTION dbo.CalculateWarranty (
@purchase_date DATE
)
RETURNS INT
AS
BEGIN
DECLARE @warranty_duration INT;
DECLARE @warranty_remaining INT;

-- Set the warranty duration to 3 years (in days)
SET @warranty_duration = 1095;

-- Calculate the remaining warranty duration in days
SET @warranty_remaining = DATEDIFF(DAY, @purchase_date, GETDATE());

-- If the remaining warranty is within 3 years, return the remaining duration; otherwise, return NULL
IF @warranty_remaining <= @warranty_duration
RETURN @warranty_remaining;

-- Default return statement (return NULL if warranty is not within 3 years)
RETURN NULL;
END;
select dbo.CalculateWarranty(DATEADD(DAY,-1098, getdate()));
(No column name)
null
SELECT dbo.CalculateWarranty(CONVERT(DATE, GETDATE()))
(No column name)
0
select dbo.CalculateWarranty(NULL);
(No column name)
null