Ssrs date/time parameter to default to first date from a dataset - sql-server

I have a dataset called "activities" which is written in SQL and in this dataset there is a field called "created on".
When the report is executed it currently has date to and date from parameters in order to filter and only show records based on the selected dates.
What I require is the "start date" parameter to default to the first activities "created on" date.
E.g. Report executed and has multiple activities.
Activity a created on= 01/01/2017,
Activity b created on= 02/01/2017,
Activity c created on = 03/01/2017
Result:
The start date parameter when the report is executed should default to 01/01/2017.

You can't have a default parameter that uses and expression. So you can't do this =Min(Fields!MyDateField.Value, "DataSet1") as you might expect. As this dataset depends on parameters, it's not available before the report is executed.
Instead you will need to create another dataset that provides the default value.
Create a new dataset (e.g. dsStartDate)
Set the datset query to be something like SELECT MIN(myDateColumn) as StartDate FROM myTable
In your parameter properties, go to "Default Values", choose "Get values from a query"
Select dsStartDate as the dataset and StartDate as the Value field.
That's it.

Related

Can SSRS dataset have a default value?

My SSRS report has one dataset (datasetMacys) that calls usp_GetStoreSales #Rundate, #StoreName.
Can the dataset have a default value? That way the report will only ask for one parameter (#Rundate) and the dataset has the string value "Macys" embedded?
In other words, the user will not have to select a value for the second parameter because it's already the default value of that dataset.
I would then add a 2nd dataset (datasetSears) where the default value for #StoreName is "Sears", which means it will only use the #Rundate that the user selected.
The stored procedure looks like this, even though it's not really needed for the question:
create procedure usp_GetStoreSales
(
#RunDate date,
#StoreName varchar(10)
)
as
select * from [Sales]
where RunDate = #RunDate and StoreName = #StoreName
I can easily fix this problem by creating two different stored procedures (ie. usp_GetMacysSales #RunDate and usp_GetSearsSales #RunDate), but that's exactly what I want to avoid.
You just need to create your two datasets and then, for each dataset, righ click the dataset name, choose properties, click the parameters tab and overwrite the parameter value for the StoreName parameter.
Yes - you can have a default value for the parameter of a dataset.
In the Parameters tab of the Dataset Properties, you can type in (hard code) a value in the Parameter Value expression box.
Of course the next question would be WHY? There may be better ways to do it.
If you are going to have both sets of data, why not make a query that combines the data into one so you only have one dataset?

How can I select a date from a table and pass it in as a parameter in SSIS?

I have one single date in one table. I am trying to select this date and pass it into a function that pulls data from another system, based on this date parameter. I think it should be something like this.
Declare #dateCurrent as DateTime
Set #dateCurrent = MyDate
SELECT #dateCurrent = DATEADD(Day,-1,CONVERT(VARCHAR(6),#dateCurrent,112)+'01')
Select top 1 ASOFDATE
FROM dbo.fn_ExtractRawData('all', 'all', #dateCurrent)
I set 'MyDate' as a Variable. I'm not sure if this is the right way to do it. Or, should I simply select the date from the table, like this.
Select AsOfDate
FROM DATE_RAW_DATA
No matter what I try, I'm getting an error that SSIS can't execute the query because the date parameter isn't coming in. How can I get this setup correctly? Thanks.
First, create an Execute SQL Task that gets the date value from your table and saves it into your variable.
Next, create another Execute SQL Task that is connected after the first task, and then use your variable in the query. Assuming you have the date saved in a variable named MyDate, your query for the second SQL Task would look like this:
SELECT TOP 1 ASOFDATE
FROM dbo.fn_ExtractRawData('all', 'all', DATEADD(DAY,-1,CONVERT(VARCHAR(6),?,112)+'01'))
The question mark in the query means you're going to be using an input parameter for that value. So once you have the SQLStatement field value set, click on the "Parameter Mapping" option in the left pane of the Execute SQL Task Editor. For "Variable Name", select your variable from the drop down list, and for "Parameter Name" put 0 (which corresponds to the first question mark in the query). Make sure the variable data type and size are set correctly.

How do I establish a parameter in SSRS report

I am new to SSRS.
I have a dataset that pulls in values from a table and displays them in a report.
One of these columns in the dataset is the "Date_Recieved" column.
I want to add a "start" and an "end" [calendar date selector] that will filter the rows displayed on the report if they fall between the "Start Date" or "End Date".
In other words I want to filter the rows displayed in the report based on whether the value they contain for the "Date_Recieved" column falls between the start/end date that the user has selected.
How is the dataset being populated? Raw SQL or a View or a Stored Procedure? as this will change how the solution will be?
If you are using a Stored Procedure.
You will need to setup two parameters #startDate and #endDate.
The stored procedure will have two parameters and you pass these into the data set via the parameter tab on the dataset menu.
If you are using a View or RAW SQL you will need to add a where clause to the SQL like such:
Where cast(Date_Recieved as date) between #parameter1 and #parameter2
then in the parameters section of the dataset options you will see these two appear and populate them with the #start and #endDate.

SSRS changing values based upon other values

I have ran into a problem with my report.
This drop down needs to adjust the values in the PeriodStart/PeriodEnd
When the Weekly Period is changed, these values need to change. Although, I want to keep the default values before Weekly Period is changed.
So lets say that the drop down has its value as 10/1/12 | 10/7/12. I am assuming I will change the expression of the two date fields and do some kind of split on the drop down value, but I am not sure what that would be. This is where I need guidance. Thanks
I am not near Report Builder right now, but it should go something like this:
1) make your weekly period drop down a datetime field with the value of the start date, and the label in whatever format you like.
2) set your period start date parameter to be a datetime field, and in the Default Values tab, set the default value to be the expression =Parameters!WeeklyPeriod.Value
3) set your period end date parameter to be a datetime field, and in the Default Values tab, set the default value to be the expressions =DateAdd("d", 7, Parameters!WeeklyPeriod.Value)

srss data query parameter / variable

how can i pass a value from one dataset value as a variable/parameter into another dataset query to populate a table cell?
eg. Table displaying DataSet1 results. Last column comes from DataSet2 which has following query
SELECT * FROM tbl WHERE = $1
The WHERE value I want to come from a field value from DataSet1 resultset. How can I do this?
Thanks
You should be able to set up an internal parameter with your other dataset using "Default Values" "Get values from a query", then reference this parameter in your other dataset. Note your SQL Syntax needs correction in the WHERE clause. Note you may see an error if the dataset to be populated executes before the populating dataset.
If your second table is in a subreport, you can pass the field from your first query by simply referencing it as a parameter in the subreport:
=Fields!DataValue.Value

Resources