Hi everyone,

I have a query as -

select DateName(Month,Date), avg(NetAmount) as AverageCustomerBill from salesmaster
group by DateName(Month,Date)

which gives result as follow -

April 451.5664
August 432.6227
July 441.1437
June 429.9915
May 423.7198
November 407.4123
October 425.1684
September 416.3678

As u can see here Months are not in proper sequence.....

Is there any way How I can get result in proper sequence of months

exa -

April --1212
May --32659
June --5478745
July --534658
August --3236
September --
October --
November --
December --

and so on...

there are two things i can think of first

SELECT     DATEPART(Month, DATE) AS month, DATENAME(month, DATE) AS Name, avg(NetAmount) as AverageCustomerBill from salesmaster 
GROUP BY DATEPART(Month, DATE), DATENAME(month, DATE)
ORDER BY DATEPART(Month, DATE)

the other one

SELECT     CASE DATEPART(Month, DATE) 
                      WHEN 1 THEN 'January' WHEN 2 THEN 'February' WHEN 3 THEN 'March' WHEN 4 THEN 'April' WHEN 5 THEN 'May' WHEN 6 THEN 'June' WHEN 7 THEN
                       'July' WHEN 8 THEN 'August' WHEN 9 THEN 'September' WHEN 10 THEN 'October' WHEN 11 THEN 'November' ELSE 'December' END AS month, 
                      avg(NetAmount) as AverageCustomerBill from salesmaster 
GROUP BY DATEPART(Month, DATE)
ORDER BY DATEPART(Month, DATE)

regards

there are two things i can think of first

select     datepart(month, date) as month, datename(month, date) as name, avg(netamount) as averagecustomerbill from salesmaster 
group by datepart(month, date), datename(month, date)
order by datepart(month, date)

the other one

select     case datepart(month, date) 
                      when 1 then 'january' when 2 then 'february' when 3 then 'march' when 4 then 'april' when 5 then 'may' when 6 then 'june' when 7 then
                       'july' when 8 then 'august' when 9 then 'september' when 10 then 'october' when 11 then 'november' else 'december' end as month, 
                      avg(netamount) as averagecustomerbill from salesmaster 
group by datepart(month, date)
order by datepart(month, date)

regards

thanks a lotttt.........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.