Query Assistance

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I have the following Query
Code:
SELECT Format([Adate], 'mmm, yyyy') as [A]
FROM [DETAIL]
WHERE [SomeThing]='Blah'
GROUP BY [Adate]

However, the results come back as...

Jan, 2008
Jan, 2008
Jan, 2008
Feb, 2008
etc...

I am looking to get
Jan, 2008
Feb, 2008
Mar, 2008
etc...
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,
Group by the same expression as in your SELECT:
GROUP BY Format([Adate], 'mmm, yyyy')

That should get you the right result I think,
ξ
 
Upvote 0
That is correct, these are text values and your date format is not suitable for sorting as text. If possible, prefer to use real dates - you can still display dates as mmm yyyy. For instance:
Code:
SELECT DateSerial(Year([Adate]),Month([Adate])+1,0) as [A]
FROM [DETAIL]
WHERE [SomeThing]='Blah'
GROUP BY DateSerial(Year([Adate]),Month([Adate])+1,0)
ORDER BY DateSerial(Year([Adate]),Month([Adate])+1,0)

I guess it depends on what you are really doing here.
 
Upvote 0
That is correct, these are text values and your date format is not suitable for sorting as text. If possible, prefer to use real dates - you can still display dates as mmm yyyy. For instance:
Code:
SELECT DateSerial(Year([Adate]),Month([Adate])+1,0) as [A]
FROM [DETAIL]
WHERE [SomeThing]='Blah'
GROUP BY DateSerial(Year([Adate]),Month([Adate])+1,0)
ORDER BY DateSerial(Year([Adate]),Month([Adate])+1,0)

I guess it depends on what you are really doing here.

Thanks, I will give this a try on Monday.
 
Upvote 0

Forum statistics

Threads
1,203,461
Messages
6,055,561
Members
444,799
Latest member
CraigCrowhurst

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top