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: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
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


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 10:00 AM
Points: 8,551, Visits: 9,043
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: Today @ 4:35 AM
Points: 1,712, Visits: 6,238
"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: Sunday, November 10, 2013 9:48 AM
Points: 36, Visits: 74
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: 2 days ago @ 11:39 PM
Points: 1,015, Visits: 1,289
@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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, April 27, 2014 6:26 AM
Points: 1,521, Visits: 3,036
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
Posted Monday, June 16, 2014 7:57 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 7:13 AM
Points: 2,381, Visits: 176
Used to use this all the time but not so much anymore.
Post #1581135
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse