TonyP
TonyP

Reputation: 5873

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 recognized datename option.

What is wrong here ? Where is Bill...

Upvotes: 0

Views: 951

Answers (4)

Madhivanan
Madhivanan

Reputation: 13700

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')  

Upvotes: 0

gbn
gbn

Reputation: 432271

My local BOL with the same link is quite clear what a "datepart" is

MSDN screenshot

Note: some DATENAME calls return numbers for Far Eastern languages

Upvotes: 1

Chandu
Chandu

Reputation: 82913

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') 

Upvotes: 5

Quassnoi
Quassnoi

Reputation: 425371

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

Upvotes: 2

Related Questions