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.
| Author |
Topic |
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2006-11-09 : 03:25:54
|
| Hi, I have a table with field Msg_Time. In this field some records are there with date and time. For eg:- 11/7/2006 2:35:00 AM, 11/1/2006 2:35:00 AM, 10/15/2006 2:35:00 AM, 11/7/2005 2:35:00 AM,11/7/2005 2:35:00 AM, 8/26/2005 2:35:00 AM,3/2/2005 2:35:00 AM etcI wrote the query like this"select datepart(year, Msg_Time) from C20_Messages"This query result is:-2006200620062005200520052005Here I want to get only the year part without repeating.I mean 20052006 How to do pls help mewith regardsshaji |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-09 : 03:27:05
|
| select DISTINCTdatepart(year, Msg_Time) from C20_Messagesorder by datepart(year, Msg_Time)Peter LarssonHelsingborg, Sweden |
 |
|
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2006-11-09 : 03:33:03
|
Dear Peter Larsson,Thanx a lot. Its working...fineShajiquote: Originally posted by Peso select DISTINCTdatepart(year, Msg_Time) from C20_Messagesorder by datepart(year, Msg_Time)Peter LarssonHelsingborg, Sweden
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-09 : 04:24:37
|
you can also use year(Msg_Time) KH |
 |
|
|
|
|
|
|
|