Solved Multiple MonthName() in a Single Query using MS Access? (1 Viewer)

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
Hello to everyone who's in the query forums! I'm a new user here. Really new, that I have to ask if it's possible to do multiple MonthName() in a single query.

I'm trying to produce an output where the numerical months turn to MonthName(), but alas. Only 1 month is being shown. Here's what I've done so far:

SQL:
SELECT Year(#11/3/2023#) AS [Year], MonthName(1) AS [Month], Count(*) AS Total
FROM admissions
GROUP BY Month([admission_date])
ORDER BY Month(admission_date);

End goal is to count the number of admitted patients(admissions) by year(2023) and month(MonthName()).
 

Attachments

  • 2668065A-FF82-41FE-8117-FFA777E43AE7.jpeg
    2668065A-FF82-41FE-8117-FFA777E43AE7.jpeg
    522.2 KB · Views: 59

Minty

AWF VIP
Local time
Today, 22:09
Joined
Jul 26, 2013
Messages
10,371
You could try something like

SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
WHERE  Year([admission_date]) = 2023
ORDER BY Month(admission_date);

Or even simply use

Format ([admission_date], "yyyy-mmm") as [Year-Month],
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
You could try something like

SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
WHERE  Year([admission_date]) = 2023
ORDER BY Month(admission_date);

Or even simply use

Format ([admission_date], "yyyy-mmm") as [Year-Month],
Interesting suggestion! Let me try this out~ thanks!
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
You could try something like

SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
WHERE  Year([admission_date]) = 2023
ORDER BY Month(admission_date);

Or even simply use

Format ([admission_date], "yyyy-mmm") as [Year-Month],
Hi, Minty! An update to your suggestion:

I have a syntax error with the FORMAT and WHERE part. I forgot to share that I'm using MS Access 2019.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:09
Joined
May 7, 2009
Messages
19,245
the query (FinalQuery) on the demo is Crosstab query.
so at a glance you can see total count of admittance by month.

and also see Query2.
 

Attachments

  • ospital_ng_maynila.accdb
    516 KB · Views: 88
Last edited:

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
the query (FinalQuery) on the demo is Crosstab query.
so at a glance you can see total count of admittance by month.
Didn't expect a fellow Filipino here! Hey there! Let me check the query of OsMan.

For now, isn't MS Access powered by JetSQL?
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
i'm not sure, or maybe ACE engine?
I believe I recall it was JetSQL.

For now, I plan to do a single column showing all of the months in word format. The PIVOT shows separate tables from your OsMan example. Might I ask if the guide from sql-practice or W3Schools actually helpful in learning MS Access syntax? Most of the other websites only have guides for SQL Server or MySQL.
 

Minty

AWF VIP
Local time
Today, 22:09
Joined
Jul 26, 2013
Messages
10,371
Sorry written on the fly, the where clause is in the wrong place
SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
ORDER BY Month(admission_date);
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
Sorry written on the fly, the where clause is in the wrong place
SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
ORDER BY Month(admission_date);
It's OK! No rush~ I know how busy you must be at this time. I thank you for doing your best to assist!
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
You could try something like

SQL:
SELECT Year([admission_date]) AS [Year], Format ([admission_date], "mmm") as [Month], Count(*) AS Total
FROM admissions
GROUP BY Year([admission_date]), Format ([admission_date], "mmm")
WHERE  Year([admission_date]) = 2023
ORDER BY Month(admission_date);

Or even simply use

Format ([admission_date], "yyyy-mmm") as [Year-Month],
Let me try uploading a photo of the sample output:
 

Attachments

  • DEF78A80-CE4C-4C19-B821-7BCBF539FB09.jpeg
    DEF78A80-CE4C-4C19-B821-7BCBF539FB09.jpeg
    522.2 KB · Views: 59

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
the query (FinalQuery) on the demo is Crosstab query.
so at a glance you can see total count of admittance by month.

and also see Query2.
Here’s the sample month column I need as an output.

Microsoft website states that the use of MonthName(Month, [abbreviation]) is the right way of converting numerical to word context, but I can’t seem to make it work under the SELECT statement.
 

Attachments

  • 2C6D7AB5-68E9-4C05-BC8B-A2AE25595231.jpeg
    2C6D7AB5-68E9-4C05-BC8B-A2AE25595231.jpeg
    522.2 KB · Views: 60

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:09
Joined
Feb 28, 2001
Messages
27,188

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
The Access Connectivity Engine (ACE) came out in 1992. Before then, you had the Joint Engine Technology engine (JET). However, ACE is merely a specific version/update of JET that became the default Access engine in Ac2007.
Interesting. If ACE is a specific version of JET, does that mean Access really is powered by JetSQL, not AceSQL?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:09
Joined
Feb 28, 2001
Messages
27,188
In the sense that even Microsoft's published literature calls the current engine "ACE" I would say "no." MS can call it whatever they like, and if they feel it deserves another name than JET, it IS their engine after all.
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
In the sense that even Microsoft's published literature calls the current engine "ACE" I would say "no." MS can call it whatever they like, and if they feel it deserves another name than JET, it IS their engine after all.
That's new information for me! Thank you! Same goes for you, @arnelgp !
 

Minty

AWF VIP
Local time
Today, 22:09
Joined
Jul 26, 2013
Messages
10,371
Final version ?

SQL:
SELECT Year([admission_date]) AS [Year], MonthName(Month([admission_date])) as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year(admission_date),  MonthName(Month(admission_date))
ORDER BY Month(admission_date);
 

tltanhueco1990

New member
Local time
Tomorrow, 05:09
Joined
Mar 15, 2023
Messages
29
Final version ?

SQL:
SELECT Year([admission_date]) AS [Year], MonthName(Month([admission_date])) as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year(admission_date),  MonthName(Month(admission_date))
ORDER BY Month(admission_date);
Thanks again for responding!

I also had this syntax error with the MonthName() part where it states the message:

"Your query does not include the specified expression 'Month(admission_date)' as part of an aggregate function."

Which is strange because I have an 'admission_date' on my admissions table, but no specific column for the months.
 

Minty

AWF VIP
Local time
Today, 22:09
Joined
Jul 26, 2013
Messages
10,371
Oh fiddlesticks
SQL:
SELECT Year([admission_date]) AS [Year], MonthName(Month([admission_date])) as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year(admission_date),  MonthName(Month(admission_date)), Month([admission_date])
ORDER BY Month(admission_date);
 

ebs17

Well-known member
Local time
Today, 23:09
Joined
Feb 7, 2020
Messages
1,946
SQL:
SELECT Year([admission_date]) AS [Year], MonthName(Month([admission_date])) as [Month], Count(*) AS Total
FROM admissions
WHERE  Year([admission_date]) = 2023
GROUP BY Year(admission_date), Month(admission_date)
ORDER BY Month(admission_date)
 

Users who are viewing this thread

Top Bottom