Reputation: 215
I want to create a statistics query (display the number of records per month).
The problem is that I want the month displayed in letter such as January, February, March, etc. not like 1, 2 or 3. I is not displaying month name in alphabet using month(getdate()
.
I don't know how can I do the conversion. Here is my SQL Server query:
select count(*) [Total], month(date) [Mois]
from user
where year(date) >= 2018
group by month(date)
order by month(date) desc
Upvotes: 2
Views: 6232
Reputation: 1269793
I imagine that the query that you want is:
select year(date), datename(month, date), count(*) as total
from user
where year(date) >= 2018
group by year(date), datename(month, date)
order by min(date);
Notes:
where
suggests that the query could return more than one year.date
value in each group.Upvotes: 1
Reputation: 5643
You should try something like this
select convert(char(3), [date], 0)
select datename(month, [date])
Upvotes: 3