x
login about faq Site discussion (meta-askssc)

SSRS default date 20th of month

Hello I've converted a spreadsheet into a SSRS report which is run on the 20th of month and I need to pass the 20th of the current month as a default value (start date). If the 20th falls on a Saturday, default to friday 19th. If the 20th falls on Sunday default to Friday 18th. How do I do this and what is the best way of doing it?

more ▼

asked May 31 '11 at 05:47 AM in Default

jhowe gravatar image

jhowe
919 29 42 46

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Personally, I would handle this within the stored procedure and not try and work this out in SSRS.

This code snippet shows how to determine a startdate according to your rules. Note that in my environment the week starts on a Sunday (i.e.@@DATEFIRST = 7) - if you have a different start to the week you will need to adjust the values.

declare @d datetime
--set @d = '20 august 2011' -- saturday
set @d = '20 November 2011' -- sunday

select @startdate = case 
                 when DATEPART(dw,@d) = 7 --Saturday
                   then @d-1
                 when DATEPART(dw,@d) = 1 -- Sunday
                   then @d -2
              else @d    
              end

select @startdate
more ▼

answered May 31 '11 at 05:59 AM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 38 43 69

I don't own the db so would rather not have to create stored procs if possible... also when declaring date time it needs to be 20th of the current month not a historical or set date.

May 31 '11 at 06:14 AM jhowe

substitute the hard coded date for getdate() function

May 31 '11 at 06:47 AM megamanblue

I presumed there was user input specifying dates, with an optional default

May 31 '11 at 06:59 AM Kev Riley ♦♦

Can you not change the report SQL at all? It sounds like you can't as the report exists, but you have a specific requirement to call it with specific parameters - is this right?

May 31 '11 at 07:02 AM Kev Riley ♦♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1601
x599
x486
x95

asked: May 31 '11 at 05:47 AM

Seen: 921 times

Last Updated: May 31 '11 at 05:47 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.