Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Rebuild master and restore system databases from complete disk failureCopy SQL Server Database »
    comments

    For reports that requires start and end dates as parameters, typically the default dates are set as today and today + 1 day or today + 1 month. Instead it might be a good idea to pick up the start and end dates from the database. This way the user will not have to play the guessing game of trying different date ranges to generate a valid report.
    To do this, create a new dataset. Paste the below query

    1. Declare @joindate datetime
    2. select @joindate = max(joindate)  from employees
    3. select cast(convert (varchar(10),dateadd(dd,-(day(@joindate)-1),@joindate),101) as datetime) as startdate,  cast(convert(varchar(10),dateadd(dd,-day(dateadd(mm,1,@joindate)),dateadd(mm,1,@joindate)),101) as datetime) as enddate

    Next on the Reports Parameters window, set the default values as - From Query and select the Start and End dates.

    Next time when you run the report, the start and end dates will be picked up from the database. You can use these dates to generate the report by default.

    2089 views
    Instapaper

    7 comments

    Comment from: Ted Krueger (onpnt) [Member]
    *****
    Ted Krueger (onpnt) Wonder how performance would add up on report execution time for using this vs Now() and a bunch of nasty function methods.
    04/14/09 @ 10:05
    Comment from: pmch22 [Member] Email
    pmch22 The date functions are called just on a local variable. performance would be impacted if the functions were called on a database column.
    04/14/09 @ 10:11
    Comment from: SQLDenis [Member] Email
    SQLDenis you might have switched start and enddate around

    run this in the adventureworks database

    DECLARE @joindate DATETIME
    SELECT @joindate = MAX(hiredate) FROM HumanResources.employee

    SELECT @joindate,
    CAST(CONVERT (VARCHAR(10),DATEADD(dd,-(DAY(@joindate)-1),GETDATE()),101) AS DATETIME) AS startdate,
    CAST(CONVERT(VARCHAR(10),DATEADD(dd,-DAY(DATEADD(mm,1,@joindate)),
    DATEADD(mm,1,@joindate)),101) AS DATETIME) AS enddate
    04/14/09 @ 11:28
    Comment from: pmch22 [Member] Email
    pmch22 Correction -I replaced getdate() with @joindate. Thanks Dennis.
    04/14/09 @ 12:05
    Comment from: Christiaan Baes (chrissie1) [Member]
    *****
    Christiaan Baes (chrissie1) I guess we are talking SSRS here.
    04/14/09 @ 15:30
    Comment from: Christiaan Baes (chrissie1) [Member]
    Christiaan Baes (chrissie1) SOmeone changed the title while I wasn't watching ;-) sneaky ;-)
    04/14/09 @ 15:34
    Comment from: pmch22 [Member] Email
    pmch22 LOL ! Chrissie , your comment made me realise I should be more explicit ! :-)
    04/14/09 @ 15:36

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)