Sql 2008 r2 - Datename
This is copied ditto from example given in Sql2008 R2 doc - Syntax: DATENAME (datepart ,date )
SELECT DATENAME(datepart,'2007-10-30 12:15:32.1234567 +05:10')
And it throws
Msg 155, Level 15, State 1, Line 4
'datepart' is not a r开发者_如何学JAVAecognized datename option.
What is wrong here ? Where is Bill...
You should specify what part of the date you want in the place of datepart parameter. Check this link:
http://msdn.microsoft.com/en-us/library/ms174420.aspx
So in case you need year part of the date it would be:
SELECT DATENAME(year,'2007-10-30 12:15:32.1234567 +05:10')
What is wrong here?
This is not supposed to be copied and run.
You should substitute datepart
with any of the valid options given under the example your copied (year
, quarter
, month
etc).
Where is Bill...
http://en.wikipedia.org/wiki/Bill_Gates%27_house
My local BOL with the same link is quite clear what a "datepart" is
Note: some DATENAME calls return numbers for Far Eastern languages
Also note that DATENAME will return data as a varchar datatype. Use DATEPART function which retunrs data as integer datatype
SELECT DATEPART(year,'2007-10-30 12:15:32.1234567 +05:10')
精彩评论