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 2005 Forums
 Transact-SQL (2005)
 Organize records

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-30 : 10:23:45
Hello,

I have an SQL 2005 table named posts.
In this table I have a DateTime Column named PublishedDate.

I need to display, on a web page, the following:
1. All posts for a given month;
2. A list of months and years with the number of posts per month:
2007
March(20)
February(15)
January(10)
2006
December(12)
November(15)
...

I suppose I need 2 SQL queries:
1. Get posts for a given month.
How can I do this?
Is it possible to pass a month and year as a parameter?

2. Get the number of posts organized by month and year.
How to do this?

I will display it on an Asp.Net TreeView.

Thanks,
Miguel

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-30 : 10:28:18
SELECT YEAR(PublishedDate), MONTH(PublishedDate), COUNT(*) AS POSTS
FROM Table
GROUP BY YEAR(PublishedDate), MONTH(PublishedDate)


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -