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

Merge Month and DateName 1

Status
Not open for further replies.

briesen

Technical User
May 13, 2008
24
US
I have a query that lists the aggregate Month and DateName by month in two separate fields. I would like to merge these together so this query displays like so:

2009 1-January
2009 2-February
etc.

Code:
SELECT  'Year'=Year(vtr."Billing Date"),

'Month'=Month(vtr."Billing Date"),

'Monthy'=DateName(month, vtr."Billing Date"),

'Count'=COUNT(vtr.[Order Number]),

'Miles'=SUM(vtr."TotalMiles"),

'Total Cost'=SUM(vtr.TotalARAmt)
       
FROM    DB1.dbo.tvr AS vtr

WHERE   vtr."CustomerShortName"=N'COMPANY'

AND (vtr."Billing Date">= CONVERT(DATETIME, '2009-01-01 00:00:00', 102))

AND (vtr."Billing Date"< DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0))
        
GROUP by Year(vtr."Billing Date"), Month(vtr."Billing Date"), DateName(month, vtr."Billing Date")

Is this possible?
 
convert(varchar(4),Year(vtr."Billing Date"))+' '+

convert(varchar(4),Month(vtr."Billing Date"))+'-'+

DateName(month, vtr."Billing Date") As DateDisplay,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top