**Puzzle:** Write a Shortest Code to Produce Zero.

It has been a long time since we have puzzle on this blog. So I have decided to post this puzzle. You have to write a shortest code which produces digit 0 (zero).

If you think this puzzle is easy, it is not true. I have two very simple but interesting condition for you.

**Condition 1: ** Do not use numbers and arithmetic calculation

**Condition 2:** Do not use 0 in the code

**Condition 3:** Do not use function len()

Well, that’s it. So if you were thinking to write code like SELECT 1-1 or PRINT 0 or SELECT LEN(”). You can’t do that. You are not allowed to use numbers, arithmetic calculation or the digit 0 in the code.

Let me show you one valid solution.

SELECT ISDATE('a')

Now, here is the challenge for you. The above code produces the result 0 (zero) and the length of the code is 18.

Here is the final condition for you,

**Condition 4:** Your Solution should have length lesser than 18 characters.

Now think of the interesting solution and post the result in the comment.

I will be happy to see what you can come up with. If you are also subscribed to my newsletter at https://blog.sqlauthority.com/contact-me/sign-up/ please expect a surprise gift for you if you get the correct answer.

Reference: **Pinal Dave (https://blog.sqlauthority.com)**

## 726 Comments. Leave new

You said shortest code that produces 0 – what you didn’t explicitly say is that it only produces 0 and nothing else. So…

$

(1 character)

“Select $” works too !!

You didn’t specify a min SQL Server version:

SELECT ISJSON(”)

(17 characters)

I also shortened yours:

SELECT ISDATE(1)

(16 characters)

Use of numbers is not allowed.

select left($,1) –length 16

Use of numbers is not allowed.

print abs(”)

Here are some examples. Choose which one you like:

select @@ERROR

select @@TRANCOUNT

select @@NESTLEVEL

select IS_MEMBER(‘sys’)

select DIFFERENCE(‘a’, ”)

select @@langid,

@@Nestlevel,

@@fetch_status,

str(”)

some of them are env specific

whats the correct answer Pinal?

SELECT @@ERROR

print str($)

What is the answer?? You said you would post it on Monday. It’s now Wed!

Well, the answers are all posted in the comment.

I did not expect to have 661 comments and I am going through all of this to make sure that I do not miss any shortest answer.

print abs($)

print $

the rules were slightly confusing. If rule #1 means no numbers at all, then rule #2 is redundant, as 0 is a number. So, assuming #2 is not redundant, that must mean that #2 does not exclude 0 somehow. The way I can see that as being true is that rule #1 excludes numbers when used with arithmetic. But it does not exclude numbers when not used with arithmetic. Or perhaps there is a subtle distinct between digit and number?

So, the selection criteria for a winner seems to be

select *

from answers

where not (usesNumbers and usesArithmetic) — Rule #1

and not (usesDigitZero) — Rule #2

and not (usesLenFunction) — Rule #3

This logic would seem to say that numbers without arithmetic are OK, and arithmetic without numbers are OK, so long at the numbers used don’t include 0.

It is unclear whether “select pi()-pi()” would be valid or not. pi is indeed a number (albeit irrational), but does not use any of the digits 0-9, and one could argue that it is not the number pi that is used, but the function pi(). So it doesn’t violate rule #1, because although it uses arithmetic it doesn’t use a number. But if you say it does violate because pi is a number, and therefore uses a number an arithmetic both, than that would mean the interpretation of ‘number’ is broader than just digits 0-9, but includes other things which are representations of numbers, such as pi, or such as $ or £.

Anyway, fun excercise. I don’t think people need to ask PInal what is “the right answer”. There could be multiple “right answers” if they are the same length and don’t violate the rules. Which rules seem open to multiple interpretations. Rather, it’s fun to just see the large variety of responses, and perhaps even learn from them.

Thank you Joe!

Actually, I am going through exactly the same feeling. There are so many right answers and so many winners :-)

Select @@ERROR

select abs(”)

SELECT ISnumeric(‘a’)

SELECT ISnumeric(”)

SELECT ISDATE(¥) –16

Doncho nailed it with 7: print $

SELECT CONVERT(int, .1)

SELECT 1^1