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

Selecting last record for a given month 1

Status
Not open for further replies.

alh1002

Technical User
Mar 27, 2006
41
US
I have a DB with daily records. I want to summarize it, and make a new table with just monthly information.

structure:
date/values/values/values ...

How do I get the values just for last entered day of a month (it won't always be the 31st)
 
SQL snippet:
WHERE [date field] = DateSerial(Year([date field]), 1 + Month([date field]), 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, that kinda works.

It is giving my the last record in January (which is on the 31st) but Feb. has only partial data. And I expect to see something listed on Feb 9th (as there was no data for the rest of Feb)

so what I want is: for the entire year 12 rows (corresponding to last entered infromation for each month)

Is there a way to fix that

here is the code as is:

SELECT ladder_date, BOM, NAV, gMTDRT, gMTDPER
FROM dailySummary
WHERE [ladder_date]=DateSerial(Year([ladder_date]),1+Month([ladder_date]),0);
 
SELECT A.ladder_date, A.BOM, A.NAV, A.gMTDRT, A.gMTDPER
FROM dailySummary AS A INNER JOIN (
SELECT Month([ladder_date]), MAX([ladder_date]) AS LastDay FROM dailySummary GROUP BY Month([ladder_date])
) AS L ON A.ladder_date = L.LastDay

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
One last issue. Different years

How do I make sure

1/30/05
is
different from
1/31/06
 
SELECT A.ladder_date, A.BOM, A.NAV, A.gMTDRT, A.gMTDPER
FROM dailySummary AS A INNER JOIN (
SELECT Format([ladder_date],'yyyymm'), MAX([ladder_date]) AS LastDay FROM dailySummary GROUP BY Format([ladder_date],'yyyymm')
) AS L ON A.ladder_date = L.LastDay

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top