Evaluating parameters in SSRS report heading - reporting-services

Hi I am trying to create a report in SSRS for a survey. The report title should have the survey date displayed. Below is what my report looks like in excel:
It has the survey date in report heading. I am trying to do similar thing in SSRS but not able to display the dates. This is what my report looks like in SSRS:
Sorry I had to blacken some of the fields. Anyways so in SSRS I created two parameters #reportStartDate and #reportNextDate. I want these parameters to be populated with yesterday's date and current date. So the param #reportStartDate should be yesterday's date and #reportNextDate should be today's date.
I tried multiple things and haven't figured out the solution yet. In the dataset properties, I assigned the following expression to the parameters:
#reportStartDate = DATEADD (DAY, DATEDIFF(DAY, 0, GETDATE()), -1)
#reportNextDate = DATEADD (DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
Here is how I created the parameters:
And here is how I assigned the parameters with expression in Dataset properties:
But after this when I preview the report, I get the error
I am working on SSRS for first time and have been struggling with this issue from almost more than a day. Any idea what I am missing or doing wrong?

Add a new dataset that contains the following
select DATEADD (DAY, DATEDIFF(DAY, 0, GETDATE()), -1) as startdate,
DATEADD (DAY, DATEDIFF(DAY, 0, GETDATE()), 0) as enddate
You should then be able to access these fields as internal in the parameter select screenReport data will look like this:
Make the parameter visibility to internal as you don't want the user to see it.
Get values from the new dataset and repeat the process for end date

I know you have accepted an answer but unless I'm mistaken it looks like a simple case of your title expression being wrong.
Your title expression should be something like
="Hotel Mobile Debrief Detail Report from " & Parameters!reportStartDate.Value & " to " & Parameters!reportNextDate.Value
There is no need to add datasets simply to display the parameter values in a text box.

Related

SSRS select parameter month and change par. first and last day of this month

i need to create parameter list of months and then (after select) recalculate two others paramateres in date format ([first day] and [last day]) of this month, can you please help me?
You are querying a database server to generate the list of months, although there's no need to do that. I suggest to rather create a list of months in the report and let the report calculate the month's names, so the language depends on the Language setting of the report (which can be the language configured in the user's browser).
For example, to calculate the Label for the Value 1, use an expression like =MonthName(1).
The Parameters FirstDay and LastDay (or just the values whenever you need them) can be calculated using these expressions:
FirstDay: =DateSerial(Today.Year, Parameters!Month.Value, 1)
LastDay: =DateSerial(Today.Year, Parameters!Month.Value, 1).AddMonths(1).AddDays(-1)

Comparing todays date against first day of the week

I am trying to set a default parameter value in SSRS report. I want to test the current date to see if it equals the first day of the week (in my case Monday). If it is the first day of week, then I want the default value to be current date minus 2 days, if it is not the first day of the week then I want the default value to be current date minus 1 day.
I seem to have a syntax problem but it doesn't tell me where. My parameters are StartDate and EndDate.
this is what I've tried:
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today(),DateAdd("d",-1,today())
this is the generic error I get:
The value expression for the report parameter 'StartDate' contains eror:[BC30201] Expression expected.
Where am I going wrong?
You are trying to use Sql syntax in a SSRS VBA expression. SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum.
So your expression needs to use VBA syntax:
=IIF(Weekday(Today, FirstDayOfWeek.Monday) = 1, DateAdd(DateInterval.Day, -2, Today), DateAdd(DateInterval.Day, , -1, Today))
It appears that you are missing a closing parentheses after the first logical part of the if statement and another to close the statement.
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today()),DateAdd("d",-1,today()))

How to get the report between certain date range in Cognos

I have recently started working on Cognos Report Studio. had a T-sql code with 4 table joins. I simply pasted the code in Cognos Report Studio by dragging the SQL toolbox to Query Explorer. The report did run successfully. But now I want this report generated on 1st of every month with maturity date falling between 1st to 30th/31st of that month.
For Eg: If I get a report on 1st May, It should give records of data where the maturity date range is between 1st may to 31st may.
I tried adding the below code to my already written SQL code:
WHERE
CURR_MATURITY_DATE BETWEEN (DATEADD(MM, 0, GETDATE()), 0) AND (DATEADD(MM, 0, GETDATE()) +1, 0) -1)
This code doesn't work.
Pl Note: THe format of column CURR_MATURITY_DATE is: mm/dd/yyyy. Please advise what changes are required in the code to run successfully.
Cognos has an add months function. (At least, Cognos 10 does.) In your expression editor, on the functions tab, it's under Business Date/Time Functions. It's called _add_months. So your function would end up being something like between (_add_months(1,current_date))
You can also use the SQL Server function. You have to put those text parameters (like MM) in curly brackets. So you would end up with dateadd({MM},0,current_date).
For the first day of the current month, in TSQL you would use:DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
In Cognos, the syntax would be DATEADD({MONTH}, DATEDIFF({MONTH}, 0, GETDATE()), 0)
Try these in your WHERE clause:
For first day of the month: select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
For last day of the month : select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate() )+1, 0))
Find it here, it explains all.

sql query to get a scheduled report to run for that curent month only

I have an SSRS 2005 report that has a dataset for to an Oracle database. The report that i have essentially just pulls all data back from an audit log. This report works perfectly fine and i have scheduled thi to run and send an email using the new subscription method within SSRS.
The only issue i have is i want the report to run on the last day of the month (its set up to do this alreday) and run the report based on that month only. Getting the report to run specifically for a month is what im unsure on? I though i would be able to set parameters within the report but these only enable my user to select a calendar date?
Is there a DATEADD or DATEPART type of function i can use to complete this task?
Regards
B
Best bet would be to set up a dynamic date default for the date patameter at the report level, and set up the subscription to use this default value, so whenever the subscription runs it would automatically have the appropriate date.
Probably the easiest thing to do is set the parameter as the current date, if that would work, e.g. something like =Today(). So that will be calculated whenever the subscription runs.
You can set the default value for whatever you need; first day of the current month, etc. You should able to set whatever value you need without too much trouble.
So for the first day of the month something like:
=DateSerial(Year(Today()), Month(Today()), 1).
Users running the report ad-hoc could just reset the parameter as required.
I'm assuming the report handles the amount of data to return correctly assuming the right data parameter is sent.
2 Parameters #DateFrom and #DateTo
Default Value for #DateFrom that outputs the first day of the current month:
=DateAdd("d",-Day(Today())+1,Today())
Default Value for #DateTo that outputs the last day of the current month:
=DateAdd("d",-Day(Today())+1,DateAdd("m",1,Today()))

Report Builder - Set datetime parameter

I have a report that has parameters StartDate and EndDate. I would like the EndDate parameter's time part to default to the end of the day when selected from the drop down.
For instance, if a user selects 5/15/2008 from the dropdown, the value shown in the box should be '5/15/2008 23:59:59' not '5/15/2008 12:00:00'
Its pretty easy to do this in .Net using the event model and a line of code but in Report Builder 2.0, what would I need to do?
Is there code that I need to write for this or did I miss some funky expression that could handle this?
Thanks.
AboutDev
I would suggest setting the default parameter in the Report Parameters section. You can get to this from Report > Report Parameters.
This allows you to set a non-queried default. There you can enter an expression like
=DateAdd(Microsoft.VisualBasic.DateInterval.Second ,-1,dateadd("d",1,Today))
That should give you a default for the end of today.
Edit: Really only useful for a single default value.
It's been awhile since I've used SSRS, so bear with me. You'll have to do a little translation, but here's what I've done in the past.
When you define your EndDate parameter, create an additional parameter named EndDateEOD, after EndDate in your list of parameters. Make this parameter a hidden value, and set it to the last moment of the day, similar to the way that Jeremy calculates it.
Then you can use #EndDateEOD in your report query where you have #EndDate now.
When StartDate is selected, you could have EndDate default to its value, so that EndDateEOD will automatically be set to the end of the start date.
Use the parameter in a DATEADD() expression in your dataset.
Rather than
...WHERE end_date = #end_date
do something like this:
...WHERE end_date = DATEADD(ms, -3, #end_date + 1)
That will go forward a day (the +1), then go back 3 milliseconds, to the last instant of the day recordable by a datetime.
You can do something like this:
=CDate(Parameters!StartDate.Value + " 23:59:59")
The part of Parameters!StartDate.Value can be any date but not the EndDate.Value itself. Eg:
- Today()
- Last day of the month from start date:
=CDate(DateSerial(Year(Parameters!StartDate.Value), Month(Parameters!StartDate.Value) + 1, 0)+" 23:59:59")
Hope this help.