If your function returns an integer, the result from isnull will also be an integer. In case the return value is null , you will have an implicit conversion to an integer for '' and this will be 0.
Try the following:
declare @xx int select isnull(@xx,'')
Result:
You may have a space if you first passed the return value from your function to varchar .
declare @xx int select isnull(cast(@xx as varchar(10)),'')
Result:
If your function returns 0 instead of null , you can use nullif to get a null value before you click on varchar .
declare @xx int = 0 select isnull(cast(nullif(@xx, 0) as varchar(10)),'')
Summary :
You need the following:
Duration = isnull(cast(FunctionA(DateA,DateB) as varchar(10)),'')
or
Duration = isnull(cast(nullif(FunctionA(DateA,DateB), 0) as varchar(10)),'')
source share