This puzzle, I have discovered accidentally. In one of the recent project, I had to display two dates next to each other. Now, when I was doing this, I accidentally did a mistake while I was typing that out. Indeed, this puzzle about strange results when adding two dates.
What I actually wanted to do was-
SELECT @date1, @date2
However, when I ended up typing was
SELECT @date1+@date2
Now I think it is very strange as the comma and the plus signs are nowhere near on a typewriter and I had ended up making this mistake.
The good thing is that I ended up learning something new which helped me build this puzzle.
Puzzle:
Let us execute the following code
DECLARE @date1 DATETIME, @date2 DATETIME SELECT @date1='2010-01-20', @date2='2016-10-22' SELECT @date1+@date2 AS result
When I executed above code I ended up with the following result-
Now my question is how come we see the result as some date in the year 2126 and not an error?
Let me know what is your answer in the comments section. I will keep all the answers hidden till Monday.
If you like such puzzles, here are three puzzles which I had published in the recent time-
- SQL SERVER – Puzzle – Shortest Code to Produce the Number 1000000000 (One Billion)
- SQL SERVER – Select Unique Data From a Column Exist in Two Different Table
- SQL SERVER – Puzzle – Write a Shortest Code to Produce Zero
Reference: Pinal Dave (https://darkslategrey-bat-805937.hostingersite.com)