Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / July 2008

Tip: Looking for answers? Try searching our database.

Dynamic Date Parameters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robin9876 - 09 Jul 2008 17:07 GMT
For a SSRS 2005 report is it possible to have a parameter which has
text values of "last month", last two months" and "last year".
Is it possible to have date range values for the ranges such as
equivalent code for Date - 1 Month, 2 Months which are passed to the
dataset?
Bruce L-C  [MVP] - 09 Jul 2008 18:36 GMT
What I do is have a list for the options. The label will say the phrase Last
Month, Last Two Months etc. The value would be an integer.
This is working T-SQL with the change to the field and table name would work
for you in Query analyzer.
declare @MonthRange as int

set @MonthRange = 1

declare @ENDDATE as datetime

set @ENDDATE = convert(varchar(2),datepart(month,getdate())) + '/1/' +
convert(varchar(4),datepart(year,getdate()))

select min(datereceived), max(datereceived), count(*) from active where
datereceived >= dateadd(month,-1*@MonthRange,@ENDDATE) and datereceived <
@ENDDATE

In the generic query tab you can do this:

declare @ENDDATE as datetime

set @ENDDATE = convert(varchar(2),datepart(month,getdate())) + '/1/' +
convert(varchar(4),datepart(year,getdate()))

select min(datereceived), max(datereceived), count(*) from active where
datereceived >= dateadd(month,-1*@MonthRange,@ENDDATE) and datereceived <
@ENDDATE

RS will create a report parameter for @MonthRange.

Or the query can be re-written as this:

select min(datereceived), max(datereceived), count(*) from active where
datereceived >=
dateadd(month,-1*@MonthRange,convert(varchar(2),datepart(month,getdate())) +
'/1/' + convert(varchar(4),datepart(year,getdate()))) and datereceived <
convert(varchar(2),datepart(month,getdate())) + '/1/' +
convert(varchar(4),datepart(year,getdate()))

Signature

Bruce Loehle-Conger
MVP SQL Server Reporting Services

> For a SSRS 2005 report is it possible to have a parameter which has
> text values of "last month", last two months" and "last year".
> Is it possible to have date range values for the ranges such as
> equivalent code for Date - 1 Month, 2 Months which are passed to the
> dataset?
Robin9876 - 24 Jul 2008 14:35 GMT
How would you be able to allow a custom date range to be used instead
of the predefined dates?

On 9 Jul, 18:36, "Bruce L-C  [MVP]" <bruce_lcNOS...@hotmail.com>
wrote:
> What I do is have a list for the options. The label will say the phrase Last
> Month, Last Two Months etc. The value would be an integer.
[quoted text clipped - 44 lines]
> > equivalent code for Date - 1 Month, 2 Months which are passed to the
> > dataset?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.