SSRS: Dataset2 not showing data inserted in Dataset1 - sql-server

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

Related

Build multiple reports with MS Report Builder 3.0

I have a program that fills 2 tables in SQL db, let's call them tUser and tItems.
tItems will contain 3 rows with a piece field, while tUser will contain 1 row with totalNoOfPieces field.
I have created a report in MS Report Builder 3.0 that shows whatever I need to, adding both those tables into my dataset, and one of the expressions there should show me Piece 1 of 3 using the above fields, for example.
I'm currently using
=CStr(First(Fields!piece.Value, "DataSet1")) + " of " + CStr(First(Fields!totalNoOfPieces.Value, "DataSet1"))
How would I make it so RB generates totalNoOfPieces identical reports for me, where the only thing that changes is the Piece x of y part?
(I guess what I'm asking is how to do it so I get 3 reports that would represent
SELECT * FROM tItems
INNER JOIN tUser ON tItems.ID=tUser.ID
in those reports)
EDIT: I should specify, I know I can add a parameter and make available values be SELECT piece FROM tItems but I'm wondering how to auto generate report for all available values.
Create a version of your report that accepts two parameters say, #CurrentPiece and #TotalPieces plus any other parameters you currently require. You don't need to setup available values for the parameters as the user will never use this report directly.
Test the report works manually by typing the parameter values in
Create a new new report that accepts a parameter #TotalPieces, plus anything else you currently need to pass to the report in step 1.
Create a dataset (say dsLoop) and set it's query definition to be the following:
dsLoop query:
DECLARE #counter int = 1
DECLARE #t TABLE (PieceNum int)
WHILE #TotalPieces>= #counter
BEGIN
INSERT INTO #t SELECT #counter
SET #counter = #counter +1
END
SELECT * FROM #t ORDER BY rownum`
Add a Matrix to your report and set the dataset property to dsLoop
Drag PieceNum from the dataset field list to the cell that says "Columns" (top right cell of matrix). This will create a column group grouped and sorted by PieceNum
In the data cell, insert a subreport and set the subreport name to be the report you created in step 1
Set the #CurrentPiece parameter of the subreport to be PieceNum (from the dataset) and set the #TotalPieces parameter to be loop report's #TotalPieces parameter.
Set any additional parameters that your subreport requires.
Set the column width to suit.
This should now give you a working report, you'll just need to tidy up/adjust anything not quite right.
If this is not clear let me know and I'll do a mock-up so you can see it in action.

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

Sql Server Reporting Services Must Declare the scalar variable #param

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

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