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.
Related
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?
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.
I'm trying to figure out the best way to go about building a dynamic query and use it as a record source for a MS Access subform. I've got my WHERE clause statically assigned at the moment just so I could get the form built and make sure data was pulling properly. The main form will have 2 text boxes formatted as ShortDate and 2 subforms below with the query results. The first subform is the query grouped by Employee name and the second subform is a sum of department totals.
FWIW this is an Access 2010 ADP/ADE front end, SQL Server 2008 back end. My current SQL for the Dept totals is as follows:
SELECT COUNT(*) AS TotalNumEstimates, SUM(NumPanels) AS TotalNumPanels, SUM(PriceBase) AS TotalBasePrice, SUM(PriceBase) / SUM(NumPanels) AS ValuePricePerPanel
FROM dbo.tblBid
WHERE (Date > CONVERT(DATETIME, '2016-01-01 00:00:00', 102))
HAVING (SUM(NumPanels) > 0)
I plan on changing the WHERE clause to "WHERE Date BETWEEN #FromDate and #ToDate". Then on the Access form when the dates are set and a "Run Report" button is clicked, programatically set the OnClick event to pass the txtFromDate and txtToDate to the #FromDate and #ToDate respectively, but I can't quite figure that part out.
The only other option I can see would be to type out the whole SQL statement as a string with the txtFromDate and txtToDate declared in the OnClick event and change the subform record source to the new string. Is there a better way to go about doing this?
I believe I have figured out my initial problem of passing the textbox to the WHERE clause by creating a stored procedure. I will repost if I can't get the stored procedure to work, but it seems easy enough.
Use a [permanent] temporary table, which you then remove when the form unloads. If multiple users will use the form simultaneously, you'll need to add a session number of some sort to the name. So:
SELECT COUNT(*) AS TotalNumEstimates, SUM(NumPanels) AS TotalNumPanels, SUM(PriceBase) AS TotalBasePrice, SUM(PriceBase) / SUM(NumPanels) AS ValuePricePerPanel
INTO dbo.TempSubFormTable
FROM dbo.tblBid
WHERE Date > '2016-01-01'
HAVING SUM(NumPanels) > 0
Remove the recordsource from your subform, and give it a public interface:
Public Sub SetRecordSource(tbl as string)
Me.RecordSource = "SELECT * FROM tbl" 'ORDER BY ...
End Sub
Then, before the temporary table is created, make your subform invisible. After creating the temporary table,
Me.subformName.Visible = True
Me.subformName.SetRecordSource temporary_table_name 'without the dbo. part of the name
I have two datasets namely Dataset1 and Dataset2.
Dataset1 is a query type of "Stored Procedure". The sp "TestProcpk" is selected and parameter "value" is mapped to it.
TestProcpk query:
Create procedure TestProcpk #value varchar(20)
as
insert into testProc select #value
Dataset2 uses the above table as below (Dataset2 fields are used in the report display):
select value from testProc
where value = #value
Expected
Note: table "testProc" is empty.
While running the report I select parameter value as "ABC". The report should display value "ABC".
Why Dataset2 is not reflecting the value "ABC" in same time? Any other workaround to achieve this.
Thanks
I believe your problem is due to SSRS running the transaction in parallel. The table isn't created from Dataset 1 when Dataset 2 is run.
In the Datasource Properties, on the General tab there is a setting for Use single transaction when processing queries. This forces the queries to run one at a time in a single transaction (great for using temp tables). Check this box and it should work as you expect. It will execute in the order of your datasets (top down).
For more info:
http://blogs.msdn.com/b/robertbruckner/archive/2008/08/07/dataset-execution-order.aspx
I have a Sql Server reporting services project. I have a dataset query called Total where I select certain data based on a parameter:
select ...
from ...
group by ...
having prop_id = #PropID
Now to populate a list of multiple values for this parameter, I have a dataset query called AllProps that selects all possible prop_id's:
select prop_id from proposal
order by prop_id
Now in the Report Data Pane I select the parameter properties from #PropID and fill out the forms as follows:
Under General I have,
Name: PropID
Data type: Text
(I select "Allow multiple values")
Under Available values I have,
Get values from a query
Dataset: AllProps
Value Fields: prop_id
label field: prop_id
Under Default Values I have,
Get values from a query
Dataset: AllProps
Valuefield: prop_id
When I click the preview tab to see my report I get the following error:
An error occurred during local report processing. An error has occurred during report processing. Query execution failed for dataset 'Total'.
MUST DECLARE THE SCALAR VARIABLE '#PropID'.
Where did I go wrong? What is scalar variable in SSRS and how is it properly used?
Thanks
The query which you have written needs to be corrected .Since you have selected multiple values you need to use in clause .
Select col1,col2....
from TableName
where prop_id in (#PropID)
in stored procedure you can directly pass the parameter and split the values using a function inside stored procedure.
if parameter is directly passed to a sql query instead of stored procedure, then concatenate the parameter values using a join and pass to datasetenter image description here