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
Answer is in your question only. SELECT ISDATE(”). Without ‘a’
select @@error
Thank you for the puzzle. My co-workers and I looked at it for a while. One of them came up with SELECT @@ERROR, which works in a new query window and also when the last query run was successful.
I didn’t have a good answer until I visited the link from your email. It brought me to the blog posting on your website where one of the related posts linked to an older puzzle looking for shortest way to get 1. From there, I came up with: PRINT SIN($)
But I wanted to know why, so I searched further. After reading https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql?view=sql-server-2017 and https://docs.microsoft.com/en-us/sql/t-sql/data-types/money-and-smallmoney-transact-sql?view=sql-server-2017, I was also able to get €, ¢, ¥, ₧, £, and ¤ to work in my SSMS.
Thank you for the learning!
select char(48)
select ceiling(”)
select floor(”)
select round(”,0)
was supposed to be
select round(”,1)
select isdate(”)
select abs(”)
Same applies for these math functions
select (”)
asin, atan, degrees, radians, sign, sin, sqrt, square, tan
SELECT @@ERROR is all I got. 15 characters
SELECT ISDATE(”) is 17 characters. By the way, yours is 18, not 19. Another possibility though it may violate the rules is SELECT STR(.4) which is only 14 characters.
SELECT @@ROWCOUNT
This returns 0 and the code has 17 characters
print sin(”)
print tan(”)
SELECT @@TRANCOUNT
Select count (null)
select \as bit
SELECT CHAR(48)
SELECT @@ERROR
select FLOOR(”)