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
or as 6th solution, variation for the 5th solution instead of select print . Has 12 chars
print day($)
SELECT ISDATE(1)
it also has 16 char code
SELECT ISNUMERIC(‘a’)
Select @@error
SELECT @@ERROR
it also has 14 char code
The least creative one I could think of:
select char (48)
While the result is not exactly a number, it still looks like a number and it has only 16 characters including spaces.
These two do their work, but sadly they are not shorter than 19 characters:
select isnumeric(‘b’)
select cast(‘False’ as bit)
This could be the one:
select ISJSON (”) => 18 characters long
What do you think?
SELECT SIN()
it also has 13 char code
PRINT @@ERROR
PRINT SIN()
it also has 12 char code
select isdate(”)
PRINT @@ERROR
it also has 13 char code
select char(48)
select str(”)
select isnumeric(”)
select char(48) — 15 characters
PRINT ISDATE(‘a’)
OR
SELECT PI()-PI()
Here is my answer,
SELECT ISNUMERIC(”)
It Produce 0 in Output.
Is that Valid Answer?
Select char(48)
select @@ERROR
Select isdate(”)