If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > order results by date not working

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-06, 11:28
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
order results by date not working

hi. i'm trying to order my results ascending by date except i'm getting some really weird output. my ouput resembles something like this:

oct 2
oct 3
sep 13
sep 21
sep 22
sep 30
aug 3
aug 5
aug 16

the data is stored in a date field. i use getdate when inserting the date to the database. is there a reason why the dates are showing up weird and not ordering appropriately? thanks for your help.

also, can you not search here any more? i keep getting timeout errors.
Reply With Quote
  #2 (permalink)  
Old 10-03-06, 12:41
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
Can you post the code you are using?
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #3 (permalink)  
Old 10-03-06, 13:03
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
Code:
SELECT Documents.MergeID, Documents.VBKey, Documents.DocumentID, 
Documents.DateCreated, Documents.[FileName] AS FileNameDesc, 
DocumentDescription.[Description] AS DocumentDesc FROM Documents 
LEFT JOIN DocumentDescription ON Documents.DocumentID=DocumentDescription.DocumentID 
WHERE Documents.VBkey="& vbkey &" AND Documents.DateDeleted IS NULL 
ORDER BY Documents.DateCreated DESC
Reply With Quote
  #4 (permalink)  
Old 10-03-06, 14:04
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Could it be that the dates hav different years in them? You could output the full date to verify that
Reply With Quote
  #5 (permalink)  
Old 10-03-06, 14:11
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
Quote:
Originally Posted by shammat
Could it be that the dates hav different years in them? You could output the full date to verify that
no, the correct years are in there. the only year in there would be 2006 for right now b/c that's when this project got started. thanks for your help though!
Reply With Quote
  #6 (permalink)  
Old 10-03-06, 14:18
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
ok. i just ran this through query analyzer and this is how it's displaying the dates:
Sep 26 2006 3:10PM

so, it looks like my dates are being arranged alphabetically???
Reply With Quote
  #7 (permalink)  
Old 10-03-06, 14:50
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Quote:
Originally Posted by bla4free
so, it looks like my dates are being arranged alphabetically?
Why do you expect them to be sorted alphabetically?
They are dates, they will be sorted like dates!
Reply With Quote
  #8 (permalink)  
Old 10-03-06, 15:19
Thrasymachus Thrasymachus is offline
SQL Server Street Fighter
 
Join Date: Nov 2004
Location: Down The Rabbit Hole
Posts: 7,979
Quote:
Originally Posted by shammat
Why do you expect them to be sorted alphabetically?
They are dates, they will be sorted like dates!
is this a datetime field?
__________________
software development is where smart people go to waste their lives
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On