|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
Thanks for the question, and thanks Hugo for your explanation.
This question was really easy, as I knew the errors couldn't happen as they were stated, so there was only one option left.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 6:35 AM
Points: 7,078,
Visits: 7,119
|
|
Nice question, terrible explanation. SQL doesn't even have a concept of default values for its various datatypes.
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
"Whenever we use any data type we should know it's default value"
I disagree (even ignoring the valid but slightly pedantic points about datatypes not having defaults).
We should never rely on default values in this way, it is prone to error, and hard to read the code.
If you want to assign a value to a date variable, then explicitly assign the value you want, don't give it a value of a different datatype and rely on implict conversion
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, July 15, 2012 11:15 AM
Points: 35,
Visits: 71
|
|
Thanks for the question.
The default value for the @date1 is NULL.
Please see below proof. If I am commenting the 'set statement, I am getting @date1 as NULL.
declare @date1 smalldatetime
--set @date1 = 0 print Isnull(@date1,getdate())
Thanks. Reji P R Hyderabad
Thanks.
Reji PR, Bangalore

|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
@rejipr1982: Hugo already mentioned this in his response. Still thanks to evaluate the same.
Thanks
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
| I cannot recall ever using smalldatetime, and now this QOD gives me good reason to avoid it. A max value in year 2079 implies that anyone attempting to save a few bytes per row with this datatype may be leaving a Y2K-like mess for a future programmer or DBA to clean up.
|
|
|
|