Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 compare only month and year part in datetime type

Author  Topic 

jjchan
Starting Member

5 Posts

Posted - 2008-05-19 : 03:10:15
hai friends,
iam doing a project in .net and using sql server.
i need to compare only month and year part in datetime type to retrive data.
1)retrive unique year and its months available in the database.
like may 2008
apr 2008
mar 2007

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-05-19 : 03:13:31
Hi try this
Select Distinct DateName(DW, Col) as 'Month',
Year(Col) as 'Year'
From tbl
Order By Col
Go to Top of Page

jjchan
Starting Member

5 Posts

Posted - 2008-05-20 : 00:11:45
thanks mate ill try this
Go to Top of Page

jjchan
Starting Member

5 Posts

Posted - 2008-05-20 : 01:04:51
it worked perfect for my need after these changes

Select Distinct DateName(mm, Col) as 'Month',
Year(Col) as 'Year'
From tbl
Order By Distinct DateName(mm, Col)


thanks once again
Go to Top of Page
   

- Advertisement -