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 2000 Forums
 Transact-SQL (2000)
 ORDER BY SQL datefield question

Author  Topic 

BrentR
Starting Member

5 Posts

Posted - 2004-10-09 : 20:19:20
I'm trying to display data by a date field (MM/DD/YYYY) in DESC ORDER from a msSQL database by using ASP. By just using the standard SQl statement: 'ORDER BY DateCompleted DESC' This only will place data in descending order of Month with out using the day and year to place them in order. I'm sure I just need to 'strip' the data for it properly display it in order but I haven't so far been successful.

I also wanted to know how to build a WHERE statement that would only show 'Events' that haven't transpired.

I appreciate any help.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-10-10 : 08:08:36
if you want to order by month, ignoring days and years, try using
order by month(DateCompleted) desc
if not then the format of the datetime column is irrelevant.

if by havent transpired u mean have DateCompleted > today use
Where DateCompleted > getdate()



Go with the flow & have fun! Else fight the flow
Go to Top of Page

BrentR
Starting Member

5 Posts

Posted - 2004-10-10 : 16:02:46
Thanks for your help. You clearly solved my second question and as for my first question I think that's basically what my results were originally. I need it to be in order first by year then month then finally day. Sorry I should have more specific in my first post. Thanks again for your help.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-10-10 : 16:43:46
what is the datatype of your date column? varchar() ? you need to use the standard SQL datetime datatype which will allow for your data to be ordered properly.

- Jeff
Go to Top of Page

BrentR
Starting Member

5 Posts

Posted - 2004-10-10 : 16:47:14
Ok that makes sense since I'm currently using varchar and now I'll switch it over to date. Thanks for the advise.
Go to Top of Page
   

- Advertisement -