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: Friday, October 10, 2014 4:59 AM
Points: 127, Visits: 133
Comments posted to this topic are about the item smalldatetime

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


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 4:43 AM
Points: 1,130, Visits: 1,391
Nice question.

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

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 2:14 AM
Points: 1,605, Visits: 5,657
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 @ 6:18 PM
Points: 6,048, Visits: 8,330
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


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, October 15, 2014 6:55 AM
Points: 880, Visits: 876
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:34 AM
Points: 3,516, Visits: 1,520
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


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:42 AM
Points: 13,295, Visits: 11,086
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: Tuesday, October 7, 2014 2:36 PM
Points: 2,818, Visits: 2,565
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 @ 6:00 PM
Points: 17,825, Visits: 15,758
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, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
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: Tuesday, October 14, 2014 5:32 AM
Points: 635, Visits: 78
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