September 9, 2011 at 1:43 am
i have to make query for following:
this would be populatede in a dropdown and passed as single parameter to SP
Today -- from 12:00:00 AM till getdate()
Yesterday -- from yesterdays 12:00:00 AM till yesterdays 11:59:59 PM
This week -- From this week's monday till today
Last week -- from last week's monday till sunday
This Month -- Firt date of current month till today
Last Month -- first date of last month till last day of past month
last 3 months -- 1st date of last 3 months till today
last 6 months -- 1 date of last 6 months till today
This year -- first Jan of this year till today
Last year -- first Jan of last year till 31-Dec of last year
No Date -- Bring all data without any date range
SP will then convert it to fromDate and Todate based on input value i.e. Today will be
Declare @FromDate datetime, ToDate datetime
if @param = 'Today'
begin
set @Fromdate =
set @ToDate = GetDate()
end
else if @param = 'Yesterday'
begin
set @Fromdate =
set @ToDate = GetDate()
end
September 9, 2011 at 2:12 am
this article should get you started
http://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply