Sql Server Reporting Services Must Declare the scalar variable #param - sql-server

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

Related

SSRS parameterized query slow on Sharepoint

Having an issue when running a report with a cascading parameter on Sharepoint.
After you enter the first parameter (#Suburb) it takes approx. 10sec before displaying the drop-down list of postcodes. Running SQL Server Profiler I can see that the actual query returns in 9ms.
The dataset is just a query, not a stored procedure, for the second parameter and looks like this:
SELECT PostCode
FROM SuburbData
WHERE Locality = #Suburb
So far I have tried the following answers found on here, such as assigning the parameter to a variable like so:
DECLARE #Locale CHAR(100)
SET #Locale = #Suburb
SELECT PostCode
FROM SuburbData
WHERE Locality = #Locale;
Adding the OPTION (RECOMPILE) hint to the end of the query.
Creating a stored procedure of the above query.
The parameter is of data type TEXT.
Why the delay in displaying the result?

Why does my Dataset display no fields in ReportServer, and can I get it to do so?

I opened a report I started in BIDS in MS SQL Server Report Builder 3.0, as I read an answer here on SO that said that was the easiest way to create a table containing all the values in a Dataset.
So I opened my .rdl file there, selected the Insert tab, then Table > Table Wizard, and the dataset from the "Choose an existing dataset in this report or a shared dataset" list.
When I select the "Next" button of the wizard, though, all lists are empty (Available fields, Column groups, Row groups, Values).
If I select "Next" again, I get, "The values field list must contain at least one field."
Those are auto-populated, though, and, as written above, are as empty as a politican's brain.
Is it because my dataset is a StoredProc, and returns data from a temp table? If so, is there a workaround?
Note: I also tried the Matrix > Matrix Wizard, with the same results.
UPDATE
Also and doubtless relatedly (no pun intended), when I try to run the report from within ReportBuilder, I see:
What a revoltin' development!
UPDATE 2
And when I return to BIDS to work on the project and try to add an Expression in a Matrix, in the Edit Expression dialog, on selecting the Dataset of interest, I get, " dataset has no fields."
Ay, caramba!
UPDATE 3
In response to lrb's answer: I don't know if my SP is really unparseable or not; it does return values from a temp table - Here is the end of it:
SELECT PLATYPUSDESCRIPTION, WEEK1USAGE, WEEK2USAGE, USAGEVARIANCE,
WEEK1PRICE, WEEK2PRICE, PRICEVARIANCE, PRICEVARIANCEPERCENTAGE
FROM #TEMPCOMBINED
ORDER BY PLATYPUSDESCRIPTION;
Could that (using a temp table) be the problem?
UPDATE 4
When adding an Expression to a textbox like so:
=Fields!PLATYPUSDESCRIPTION.Value
...I get the following fingerwag on the Preview tab:
The definition of the report 'bla' is invalid. The Value expression for the textbox 'textbox4' refers to the field 'PLATYPUSDESCRIPTION'. Report item expressions can only refer to fields within the current data set scope or, if inside an aggregate, the specified data set scope.
Surely there's a way to use results from temp tables in an SSRS report, no es cierto?
This will happen when the query or stored procedure can not be parsed with certainty. For example, if your data set is a store procedure that returns something like the following:
IF(#SomVariable=1)
SELECT 1,2,3,4
ELSE
SELECT 'A','B','C'
The above logic in a SP would be horrible, however, the field name and datatypes can not be determined. The same holds true in other edge case scenarios.
What you can do for a work around is to trick the parser by modifying your sp and offering up a clean return statement, then changing the sp back to its original form. Since the metadata is persistent until the next refresh, your values will hold. NOTE : If the problem occurs when returning temporary tables in your dataset see #4 below.
1. Modify your existing stored procedure
ALTER PROCEDURE MyProcedureThatDoesNotParse()
AS
BEGIN
/*COMMENT OUT CURRENT SP LOGIC
...
*/
SELECT
MyField1=1,
MyField2='String',
MyField3=0.01
END
2. IN SSRS Refresh the fields for your dataset.
NOTE : You will see MyField1,MyField2 and MyField3 in the fields list.
3. Revert the changes to your stored procedure.
4. For queries or SP's that return a local #temporary table, global ##temporary table or a table valued #variable, it seems that aliasing the temp structure works. I.E
SELECT * FROM #TABLE --Does not always parse in SSRS
SELECT * FROM #TABLE T --Seems to be able to be parsed by SSRS
Change command type on the report builder, choose " text " and write exec yourprocedurename. It will work

SSRS: Dataset2 not showing data inserted in Dataset1

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

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.

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