I have a dynamic SQL stored procedure returning multiple number of columns for different items.
For example, item1 - 5 columns, item2 - 4 columns
I am thinking of building SSRS reports using that stored procedure hoping to get multiple results.
For example, when click 'item1', it gives you that 5 columns sp can return whist click 'item2', it gives you that 4 columns sp can return
Can SSRS do this? When I use SP as a source for SSRS, it seems that the output is NOT dynamic as it only returns 'item1'
thanks
r
RS will read column metadata from the first result set of the query.
So I suggest you can add a table variable (fixed columns to support all your dynamic results) into your stored procedure, insert the dynamic query result into the table variable, and then select the result from the table variable.
what I did is to create a 'big table' in SSRS and manually create fields sp potentially returns and only display the columns based on the sp outputs by using 'viability' option
the only issue is that you need to manually configure each column to indicate under what circumstance it is supposed to appear
Related
In SSRS report I have two data sources from two different servers. I have a dataset for each data source and would like to return in a tablix the ids that are in dataset 1 but not in dataset 2.
So if dataset 1 has ids 1,2,3,4,5 and dataset 2 has ids 1,2,3 the report should display 4 and 5. I cannot link the servers. Thanks.
There are several ways to do this.
Common Lookup method
This is the way most people would probably do this
Use the Lookup() function.
Set the tablix row's hidden property to something like
=ISNOTHING(
Lookup(Fields!IDa.Value,Fields!IDb.Value,Fields!IDb.Value,"Dataset2")
) = False
The above, for clarity, assumes the ID column in dataset1 is called IDa and the ID column from dataset2 is called IDb. It will stil work if they have the same name (e.g. 'ID')
Note: Dataset name must be in quotes and is case sensitive.
Using this method returns all the rows and simply hides the ones that do not match your criteria. This may not be ideal if you're exporting the data. If not, see the alternative version below.
Alternative method
For reasonably small datasets - parameter method
... and because I thought it was an interesting approach...
This second method uses a hidden parameter and is easy to setup assuming you have a reasonable small number of records.
Using your example, create a parameter called List2 and set its default and available values BOTH to your Dataset2 query (from your example above). Make the parameter multi-value. You can make this parameter hidden once it's working.
Now Your Dataset1 query can be a simple query like this,
SELECT * FROM Table1 WHERE id NOT IN (#List2)
#List2 will contain the values from datset2 (1,2 and 3) so the query will return only the remaining values.
Note I named the datasets to match your example but the datasets must be created in the order above.
I'm wanting to know if it's possible to pass a variable into an SQL statement for a query, rather than making 12 different queries which would also have me making 12 different forms (1 for each query). The table name to update depends on the column "what_table" in a table named "weekinfo".
currently the SQL statement is:
SELECT wk1_info.ID, wk1_info.Player_Fname, wk1_info.Player_Lname, wk1_info.email, wk1_info.postion
FROM wk1_info
WHERE (((wk1_info.postion) Like 0));
is it possible to declare the table this way, or would I have to make the extra queries and forms? If it is possible could I pointed in the right direction?
No. Table and field names cannot be passed as parameters.
What you can do is to write the full SQL from a template string replacing tokens for table and/or fields names with those you need. Then run/execute the finished SQL string.
I'm using Report Builder 3 which runs a stored procedure and displays a simple table. Next, we would like to filter based on the first column of data. The first column of data might have 20 rows, and 3 possible values.
How can I make Report Builder display those 3 values in the parameter dropdown, without rerunning a SP or Query from the server?
(Running the SP that obtains the data takes several seconds, and it is not reasonable to rerun another query in order to populate the parameter dropdown)
What I've tried:
1) I create a parameter dropdown and select the column name as values for the dropdown. Instead of getting 3 unique values, 20 rows appears in the parameter dropdown, with duplicates corresponding to the original dataset results. How can I make them unqique?
2) Grouping by the values in the first column. Grouping works, but we would still like to display a parameter dropdown that contains unique values from column one.
I've got an ugly database structure - tables are named for fiscal years, as in GL_2011, GL_2012, etc.
I need to allow the user to tell me which fiscal year they want to get data from, then construct the table name, and then execute the query.
I've had some success with building a string assigned to #SQL_QUERY and EXECuting it.. But MS Report Builder seems to get lost in the process and often doesn't populate my fields in the dataset. Other times I get erratic errors where I am trying to piece the query together.
Simple Example:
DECLARE #SQL_QUERY VARCHAR(MAX);
SET #SQL_QUERY = 'SELECT ITEM_1, ITEM_2 FROM ' + 'GL_' + CAST(#FISCAL_YEAR_PARM AS VARCHAR(4));
EXEC(#SQL_QUERY)
Here's a suggestion. In order to have SSRS recognize the columns returned by the query, develop a stored procedure that populates a temp table and returns the rows of the temp table. Pass in the fiscal year to determine which db to query (or do it dynamically like you have) to populate the temp table. If you do that, then SSRS knows the columns that will be returned with each call, and will make those available in Builder.
I have written a complex Stored Procedure that creates tables depending on the Parameter it recieves.
My SSRS report has 7 tables that need to be populated from this Stored procedure, so i have 7 DataSets, each executing the same stored procedure but with different Parameters so that it can populate each of the tables in my report.
My problem is, and even to me it sounds silly that I wouldnt know, I need to, on each of the 7 tables being populated by the SP, Show the DataSet name used for that particular table.
Does anyone know how to display the Dataset Name of the DataSet that each tablix on my report is using?