Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ordering a converted date_stamp

Status
Not open for further replies.

seekwall

Programmer
May 14, 2001
41
GB
I am trying to run a simple query over a datestamp field defaulted with getdate(), using the convert function:

select convert(varchar(10),datestamp,103), count(*)
from table
group by convert(varchar(10),datestamp,103)
order by convert(varchar(10),datestamp,103)

The problem is that the results are only ordered by the DD part of the date.

Is there any simple solution to this problem ?

 
Try this:

select convert(varchar(10),datestamp,103), count(*)
from table
group by datestamp
order by datestamp


Rick.
 
Or try this. It does require SQL 7 or higher. The database must also be in SQL 7 or higher compatibility mode.

Select
datestamp=Convert(char(10),
convert(datetime,datestamp, 120), 103),
reccnt
From
(Select TOP 100 Percent
datestamp=convert(char(10), datestamp, 120),
reccnt=count(*)
From tblname
Group By convert(char(10), datestamp, 120)
Order By convert(char(10), datestamp, 120)) As qry Terry L. Broadbent
Programming and Computing Resources
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top