Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

blank instead of zero

Duration = isnull(FunctionA(DateA,DateB),'')

The Function above calculates number of days and if day is null it displays the value 0 instead of blank value

How can I change the above code to so that it shows blank and not 0 for value null?

like image 578
6 revs, 3 users 89% Avatar asked Nov 03 '11 17:11

6 revs, 3 users 89%


People also ask

How do I show blank instead of value?

Change empty cell display Select the For empty cells show check box. In the box, type the value that you want to display in empty cells. To display blank cells, delete any characters in the box. To display zeros, clear the check box.

Is blank then 0?

When you reference a cell in Excel, the cell reference can be blank. This means that the cell doesn't contain any data. If the cell is blank, Excel will return a zero (0) value. You can use this feature to your advantage to make sure that cells with no data don't affect your formulas.

How do you replace 0 with dashes?

To change a zero to a dash, you have to play on the 3rd argument of the code of a number. So, by adding just a dash between quotation marks in the 3rd parameter, all your 0s will be replaced by dashes.


1 Answers

If your function returns an integer the result from isnull will also be an integer. In the case the return value is null you will have an implicit conversion to integer for '' and that will be 0.

Try this:

declare @xx int
select isnull(@xx,'')

Result:

-----------
0

You can have the space if you first cast 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 cast to varchar.

declare @xx int = 0
select isnull(cast(nullif(@xx, 0) as varchar(10)),'')

Summary:

You need this:

Duration = isnull(cast(FunctionA(DateA,DateB) as varchar(10)),'')

or this

Duration = isnull(cast(nullif(FunctionA(DateA,DateB), 0) as varchar(10)),'')
like image 180
Mikael Eriksson Avatar answered Nov 09 '22 01:11

Mikael Eriksson