0

Column occurrence_limit is money datatype,

If it is NULL I want just empty string (''), but it gives me 0.00.

ISNULL(occurrence_limit,'')  as occurrence_limit

How can I simply have '' instead of 0.00?

4
  • 2
    The empty string is not a valid value for money. Why not just use null? Commented Mar 5, 2020 at 18:16
  • 2
    Don't. Simple as that. Handle it in your presentation layer. '' is not a number, so it can't be stored as a money value, and it's implicitly converted to 0. You most certainly don't want to treat your numbers as a varchar (as I can assure you that 100 is greater than 2, not less than it) so leave it as it is. Commented Mar 5, 2020 at 18:16
  • The outcome goes to excel sheet. User requirements is to have blank if NULL Commented Mar 5, 2020 at 18:17
  • 1
    So fix what ever is outputting to Excel, @Serdia . Most applications don't actually display NULL they show an empty "cell", so what ever ETL process you are using is actually putting "NULL". Fix the ETL process. It's only really IDEs that tend to display NULL, as it is different to '' when dealing with strings. Commented Mar 5, 2020 at 18:18

3 Answers 3

2

As others have said, don't do it. But if you need to:

SELECT ISNULL(CONVERT(VARCHAR(9), occurrence_limit), '') AS occurrence_limit
Sign up to request clarification or add additional context in comments.

1 Comment

Just to give reason why it's bad: it's that the values aren't numerical anymore. For important things, like money, that is a problem. '100' is less than '2', for example, and '17' + '2' is '172'.
0
DROP table #testStak create table #testStak(nombre varchar(50),moneycant money)

INSERT INTO #testStak VALUES ('ALFA',10) 
INSERT INTO #testStak VALUES ('BETA',NULL) 
INSERT INTO #testStak VALUES ('GAMMA',5000)

SELECT nombre,ISNULL(CAST(moneycant AS varchar),'') FROM #testStak

2 Comments

Not related to question
actually it does, its a form to put an empty space instead of 0.00 in a column of money.
0

Try this out:

SELECT ISNULL(NULLIF(occurrence_limit, 0),'')  as occurrence_limit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.