When I was on that step, I was wondering to run this second contest. Sometimes our basics can get tricked if we add a twist to the whole setup. Below are two sets of Queries and I would want you to guess what is the output and why?
What is the output for the below query? And why?
DECLARE @dt DATE = '0001-1-1' SELECT MONTH(@dt), YEAR(@dt)
Part of the answer is in the earlier puzzle I mentioned starting this blog. But what would the year value show? Take a guess and let me know.
I have made a small change in the default value for the second query. Now can you guess what the output from this query is?
DECLARE @dt DATE = '1-1-1' SELECT MONTH(@dt), YEAR(@dt)
As part of the hint I can tell you the MONTH function returns the same value. But there is something different for the YEAR function.
So here is the quiz – Why are the values different? What is the reason behind this?
Please leave correct answer in comment below the blog.
I will announce winner of this contest in 48 hours. Two people who give the right answer, I will share a learning resource worth USD 29 on June 11 via Email.
Reference: Pinal Dave (https://blog.sqlauthority.com)