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 Tuesday, December 28, 2010 10:03 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, June 11, 2013 3:52 AM
Points: 127, Visits: 123
Comments posted to this topic are about the item smalldatetime

Rahul
Post #1040101
Posted Tuesday, December 28, 2010 10:05 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877, Visits: 1,159
Nice question.

Thanks
Post #1040102
Posted Wednesday, December 29, 2010 2:17 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:29 AM
Points: 1,270, Visits: 4,307
Not so sure about the explanation given--smalldatetime doesn't have a "default value" of 1 Jan 1900, it's just that the underlying number that stores the date uses 0 to represent that date.
Post #1040154
Posted Wednesday, December 29, 2010 5:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:26 AM
Points: 5,296, Visits: 7,235
Good (if fairly easy) question, but bad explanation.

The default for smalldatetime is not Jan 1, 1900; it is NULL. Here is the proof:
DECLARE @d1 smalldatetime;
SELECT @d1;

Also, setting a variable to 0 is not at all requesting to set it to the default, it is requesting to set ot to the value 0, or whatever is the result of implicitly converting 0 to the data type of the variable.
DECLARE @v0 float, @v1 char(20), @v2 varbinary(max), @v3 xml, @v4 uniqueidentifier;
-- Show default values - NULL for all data types
SELECT @v0, @v1, @v2, @v3, @v4;
-- Set to result of implicit conversion of 0 to specified data type
SET @v0 = 0;
SET @v1 = 0;
SET @v2 = 0;
-- Uncomment to get conversion errors
--SET @v3 = 0;
--SET @v4 = 0;
-- Show results
SELECT @v0, @v1, @v2, @v3, @v4;




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1040202
Posted Wednesday, December 29, 2010 5:40 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Yesterday @ 5:48 AM
Points: 661, Visits: 698
Well that's what I get for second-guessing myself. It seemed like such an easy question, the obvious answer couldn't possibly have been right. Guess that'll teach me!

Ron


-----
a haiku...

NULL is not zero
NULL is not an empty string
NULL is the unknown
Post #1040211
Posted Wednesday, December 29, 2010 7:11 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 6:55 AM
Points: 3,061, Visits: 1,268
Great question.

I didn't know it beforehand, but it sure made sense when I thought the question over.
Post #1040262
Posted Wednesday, December 29, 2010 7:31 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 9,410, Visits: 6,495
Nice, easy question. And thanks to Hugo for the extra, thorough explanation.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1040276
Posted Wednesday, December 29, 2010 7:34 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,681, Visits: 2,423
Whenever we use any data type we should know it's default value


Although I will agree that knowing these things has value, I am more of the opinion of never leave anything to default, declare everything. This way the default becomes irrelevant and you are much less likely to get a surprise in your results.
Post #1040278
Posted Wednesday, December 29, 2010 9:39 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 12:32 AM
Points: 18,855, Visits: 12,439
Thanks for the question and thanks to Hugo for the explanation.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1040414
Posted Wednesday, December 29, 2010 11:04 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, March 25, 2013 8:57 AM
Points: 635, Visits: 74
When a variable is declared in SQL by default it's value will be NULL, there is no default value concept in SQL variable declaration.

Regards
Kiran
Post #1040463
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse