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
 General SQL Server Forums
 New to SQL Server Programming
 order by date ASC issue

Author  Topic 

gvmk27
Starting Member

44 Posts

Posted - 2015-01-16 : 09:47:30
I have below SQL, which should be order by posteddate ASC

SELECT AnnouncementID,[Subject],[Description],
CONVERT(nvarchar(10),PostedDate,101) AS PostedDate,
CONVERT(nvarchar(10),ExpiredDate,101) AS ExpiredDate,
CountryID,CreatedBy, CreatedDate, ModifiedBy, ModifiedDate
FROM Announcements a
WHERE isActive = 1
AND CountryID = 2
AND (GETDATE()>= PostedDate)
AND (GETDATE()<= ExpiredDate)
ORDER BY PostedDate ASC


but result is displaying as below, PostedDate datatype is datetime

01/01/2015
01/02/2015
12/28/2014
12/31/2014


expected result is
01/02/2015
01/01/2015
12/31/2014
12/28/2014

mhorseman
Starting Member

44 Posts

Posted - 2015-01-16 : 10:42:39
To get your expected result (most recent first), then you need

ORDER BY PostedDate DESC

However based upon the actual result, I suspect that PostedDate is actually a character datatype.


Mark
Go to Top of Page
   

- Advertisement -