Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

smalldatetime Expand / Collapse
Author
Message
Posted Thursday, December 30, 2010 11:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, September 5, 2014 2:00 PM
Points: 2,160, Visits: 2,191
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.
Post #1041103
Posted Monday, January 3, 2011 10:41 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:17 PM
Points: 7,935, Visits: 9,662
Nice question, terrible explanation. SQL doesn't even have a concept of default values for its various datatypes.

Tom
Post #1041948
Posted Tuesday, January 4, 2011 3:15 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, December 24, 2014 5:46 AM
Points: 1,834, Visits: 6,657
"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
Post #1042261
Posted Tuesday, January 4, 2011 11:21 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, November 3, 2014 11:44 PM
Points: 39, Visits: 75
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

Post #1042601
Posted Tuesday, January 4, 2011 10:00 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 20, 2014 5:13 AM
Points: 1,131, Visits: 1,394
@rejipr1982: Hugo already mentioned this in his response. Still thanks to evaluate the same.

Thanks
Post #1042810
Posted Wednesday, January 5, 2011 7:59 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
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.
Post #1043454
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse