I have this weird encounter using CASE in sql 2014.
This is my query:
SELECT (CASE WHEN dbo.GetFunctionAge(C.Birthdate) = 0
THEN '' ELSE dbo.GetFunctionAge(C.Birthdate)
END) AS Age
,dbo.GetFunctionAge(C.Birthdate)
,c.Birthdate
FROM Client C
WHERE ClientID = '34d0d845-e3a6-4078-8936-953ff3378eac'
this is the output:
Here is the GetFunctionAge function if you might ask.
IF EXISTS (
SELECT *
FROM dbo.sysobjects
WHERE ID = OBJECT_ID(N'[dbo].[GetFunctionAge]') AND
xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].[GetFunctionAge]
GO
CREATE FUNCTION [dbo].[GetFunctionAge](@BirthDate DATETIME)
RETURNS INT
AS
BEGIN
DECLARE @Age INT
IF(@BirthDate = '1753-01-01 00:00:00.000')
BEGIN
SET @Age = 0
END
ELSE
BEGIN
SET @Age = DATEDIFF(hour,@BirthDate,GETDATE())/8766
END
RETURN @Age
END
GO
Question:
Why is Column Age in my output is 0which should be ''?
I added (No column name) to show that its output is 0 so my expected output base from my case condition is '' not 0
I didn't receive any error regarding inconsistency of data so why is case behaving like that?
Thanks for those who could clarify this to me.

''with-1?DATEtype. 2) Why notDATEDIFF(year, @BirthDate, GETDATE()), instead of using hours? 2b) The hours value is wrong - there's 8760 hours in a (365-day) year. You'd potentially have problems with DST anyways...