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
 Script Library
 Ordering by months

Author  Topic 

s_a19
Starting Member

15 Posts

Posted - 2004-06-09 : 09:50:07
I am wondering if someone maybe able to help me, I am needing to order my data via months in the calendar sense not alphabetically, below is what I currently have, but it only does it alphabetically.

select to_char(created,'yyyy-Mon'), matdesc, count(*)
from test
group by to_char(created,'yyyy-Mon'), matdesc
order by to_char(created,'yyyy-Mon') desc

any help would be greatly appreciated

Thank you

Stephen

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-09 : 09:52:04
try:

select to_char(created,'yyyy-Mon'), matdesc, count(*)
from test
group by to_char(created,'yyyy-Mon'), matdesc
order by year(created), month(created)


Corey
Go to Top of Page

s_a19
Starting Member

15 Posts

Posted - 2004-06-09 : 10:27:33
thank you,
it doesnt seem to like the fields year and month,
its complaining that they arent in the table and its saying invalid column name.
any ideas?
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-09 : 10:32:53
The functions MONTH and YEAR are valud SQL Server T-SQL function calls. Are you running this against a SQL Server database?


Raymond
Go to Top of Page

s_a19
Starting Member

15 Posts

Posted - 2004-06-09 : 10:49:42
it appears not
i do apologise
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-09 : 10:50:33
No problem! The to_char function was the giveaway...


Raymond
Go to Top of Page

s_a19
Starting Member

15 Posts

Posted - 2004-06-09 : 11:06:29
would you be able to recommend a suitable forum
for the problem please

thanks
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-09 : 11:07:59
Probably not! What language are you using?


Raymond
Go to Top of Page

s_a19
Starting Member

15 Posts

Posted - 2004-06-09 : 11:21:56
PL/SQL

Stephen
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-09 : 11:28:27
Then you'd better try an Oracle forum.


Raymond
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-06-09 : 11:30:54
[dusting off oracle books]
Did you Try MM

Do you have a manual...I know the formats are in there

[/dusting off oracle books]



Brett

8-)
Go to Top of Page

s_a19
Starting Member

15 Posts

Posted - 2004-06-10 : 04:18:42
thank you

for dusting of those books,

it appears to work
Go to Top of Page
   

- Advertisement -