Monday, 11 April 2011

Simple but overlooked - Date Text

I always forget this one!

Say you have a date 01/02/2011 but you want the month returned as text for a report

Use the datename function!

Example:

SELECT DATENAME(month, ew_event_date) Mon , COUNT(*) AS Events
FROM            EW.tbl_core_inbound
GROUP BY DATENAME(month, ew_event_date)

Returns:

Mon          Events

January     1258212
February   1120195
March       876901
April         51111

Simple, but effective
T

No comments:

Post a Comment