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 123»»»

Date data type Expand / Collapse
Author
Message
Posted Tuesday, April 27, 2010 8:45 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 7:21 AM
Points: 1,519, Visits: 1,724
Comments posted to this topic are about the item Date data type

------------------------------------------------------------
Check out my blog

http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #911591
Posted Tuesday, April 27, 2010 8:55 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, November 24, 2014 8:33 AM
Points: 1,676, Visits: 1,760
Good question, thank you. I answered correctly because I already tried it some time ago when I first learned about the new data type just to check whether behavior of date is the same with the one of datetime.

Oleg
Post #911592
Posted Tuesday, April 27, 2010 11:25 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 11:09 PM
Points: 1,940, Visits: 1,173
Iam not using sql server 2008.

so I learned one new thing today.


Malleswarareddy
I.T.Analyst
MCITP(70-451)
Post #911624
Posted Tuesday, April 27, 2010 11:27 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 7:49 AM
Points: 212, Visits: 1,117
Goodish, at least one of the requirements for QOD is fulfilled in this question statement, i.e to include the Version # of SQL.

Although it was obligatory for this question but at least i appreciate this effort and will request other contributors to make question statements clear of ambiguities specially the Version Conflicts.

Thanks !!!

Post #911626
Posted Wednesday, April 28, 2010 12:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 13,633, Visits: 11,504
Good question. No points for me but I learned something new today.
And also useful, when we will (finally) migrate to 2008.




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 #911640
Posted Wednesday, April 28, 2010 1:04 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, May 10, 2010 5:13 AM
Points: 40, Visits: 18
Hi to all,

1.
DECLARE @Today DATE
it wii not work but if you change datetype "DATE" to "DATETIME"
Then it will work

DECLARE @Today DATETIME
SELECT @Today = '01 DEC 2009'
SELECT @Today+1
SELECT @Today

2.
Directly we can't add integer value to date variable, by using DATEADD function we can add day(s)/year(s) to date variable.


Thanks & Regards
M@N@[size="7"][/size]
Post #911657
Posted Wednesday, April 28, 2010 1:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393
Mostly a good question. I got it wrong, because I was too hasty - I overlooked that the data type was DATE, not DATETIME (probably because I still work with SQL2005 on a daily basis). I do know that adding an integer to DATE is not supported.

What I dislike about the question is:
* The date format. Not all locale settings recognise "Dec" as december. (Try adding "SET LANGUAGE German;" as the first line - at least on SQL Server 2005 and with the data type changed to datetime, that results in a conversion error)
* The missing semicolons. In SQL Server 2008, not terminating statements with a semicolon is deprecated.
* There were two SELECT statements, so the incorrect answer options should have included two results sets. (I guess the author intended the first SELECT to read "SELECT @Today = @Today + 1;" - yet another reason to prefer SET over SELECT).

But the lesson learned is valuable. For me (to read carefully and think instead of just shooting from the hip), and for many others (that adding an integer to a date is not supported - just as it should never have been supported for datetime).

Thanks for the question!



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #911663
Posted Wednesday, April 28, 2010 1:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 13,633, Visits: 11,504
M@N@ (4/28/2010)
Hi to all,
DECLARE @Today DATE
it wii not work but if you change datetype "DATE" to "DATETIME"
Then it will work


Why wouldn't that work? The date datatype exists on SQL Server 2008.




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 #911671
Posted Wednesday, April 28, 2010 2:50 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 8, 2010 7:47 AM
Points: 26, Visits: 42
Gud Quest !! :) I have learnt about casting while trying to solve the error in the Quest... and by the way, can anyone give me the syntax for using 'DATEADD' function??

------------------------
~Niths~
Hard Work never Fails
Post #911708
Posted Wednesday, April 28, 2010 2:59 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 13,633, Visits: 11,504
nithya.s (4/28/2010)
Gud Quest !! :) I have learnt about casting while trying to solve the error in the Quest... and by the way, can anyone give me the syntax for using 'DATEADD' function??


Here you go:

http://msdn.microsoft.com/en-us/library/ms186819.aspx




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 #911709
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse