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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group By Date

Status
Not open for further replies.

Pamy

MIS
Oct 15, 2002
29
0
0
SG
Hi,

I would like to display the date by month using SQL statement but not sure how to write the code.
Anybody can give a piece of advise. Thks.

EG a list of dates in SQL Server
Date:
11/3/03
11/3/03
11/4/03
11/05/03

When executing the code I would like to display in the following format.

Mar
11/3/03
11/3/03

April
11/4/03

May
11/05/03



 
You could include a new calculated field using the DATENAME function:

SELECT DATENAME(month, yourdatefield), yourdatefield, yourotherfields
FROM yourtablename
GROUP BY DATENAME(month, yourdatefield), yourdatefield
 
no, that GROUP BY is illegal because it does not contain all the non-aggregate fields in the SELECT list, namely yourotherfields

grouping in the query is not required here, but DATENAME is okay

pamy, if you're using ColdFusion, what you want can be produced by the GROUP= parameter of the CFOUTPUT, but if it's something else, you will have to detect changes in the month name in your own logic


rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top