RE: write a stored procedure which return all record for last month
From: Cowboy (Gregory A. Beamer) - MVP (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 11/04/04
- Next message: Kevin Yu [MSFT]: "Re: 2nd problem with that listbox doesn't refresh after adding an"
- Previous message: Val Mazur: "Re: SQL connections"
- In reply to: Lloyd Dupont: "write a stored procedure which return all record for last month"
- Next in thread: Lloyd Dupont: "Re: write a stored procedure which return all record for last month"
- Reply: Lloyd Dupont: "Re: write a stored procedure which return all record for last month"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 3 Nov 2004 19:31:03 -0800
If you want everything for a month, you are most of the way there. Getting
the MAX(Date) is a good start. Next, you will want to use the MONTH() and
YEAR() functions to get all records where the Month of the date = max(date)'s
month and the year matches max(date)'s year. This will only give you records
for a single month.
--- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "Lloyd Dupont" wrote: > I have a blog_text table with a date column. > I'm trying to write a stored which find the month ot the last entry, and the > return all records for the month. > I'm quite new to stored procedure, can't find relevant infomation in the > documentation, and I'm not managing it.... > > If anyonw could gives me any hinth on why the below code is wrong and how to > make it both > - compile > - return last month entries... > thanks ;-) > --------- > CREATE PROCEDURE dbo.LastBlogMonth AS > > DECLARE @max_date DATETIME > > SELECT @max_date = MAX([date]) FROM galador_blog_text > GO > > SELECT * FROM galador_blog_text > WHERE [date] >= @max_date > RETURN > > GO > > >
- Next message: Kevin Yu [MSFT]: "Re: 2nd problem with that listbox doesn't refresh after adding an"
- Previous message: Val Mazur: "Re: SQL connections"
- In reply to: Lloyd Dupont: "write a stored procedure which return all record for last month"
- Next in thread: Lloyd Dupont: "Re: write a stored procedure which return all record for last month"
- Reply: Lloyd Dupont: "Re: write a stored procedure which return all record for last month"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|